Skip to content

Commit

Permalink
Fix FixedPreferencesTitleLength
Browse files Browse the repository at this point in the history
I tried to remove a `maxLength="41"` and lint was still succesful.

I finally took the time to learn how the linter works, after having
years where it is a mystery.

Given that the code was not very clear to me, I added comments, and
rewrote part of it.

I then realized that the issue was that, if the string was not found,
no error was recorded. Strings may be missing either:
* because the string is hard coded in English (developer options), in
which case I explicitly decided to ignore the strings, or
* because the string is defined outside of 10-preferences.xml

As far as I can tell, even if the string is not purely a preference,
the max length constraint should still be present outside of
preferences.

I also updated the string so that, with maxLength less than 41, the
lint still works. This is important because some strings are being
used in Menu, where the maxLength is even shorter. A future PR should
reuse this same code for menus.

I also rewrote slightly the error message, hopefully improving
them. Admittedly, given that only developers will see the errors, it
was not that important a change.

Finally, of course, I added the maxLength to every strings that were
found by the linter.
  • Loading branch information
Arthur-Milchior authored and lukstbit committed Oct 23, 2024
1 parent 3dc0b98 commit 197b2bc
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 172 deletions.
40 changes: 20 additions & 20 deletions AnkiDroid/src/main/res/values/01-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Navigation drawer items-->
<string name="decks">Decks</string>
<string name="card_browser" comment="The usage of card browser inside the app (note the casing)">Card browser</string>
<string name="card_browser" maxLength="41" comment="The usage of card browser inside the app (note the casing)">Card browser</string>
<string name="statistics">Statistics</string>
<string name="settings">Settings</string>
<string name="help">Help</string>
Expand Down Expand Up @@ -53,15 +53,15 @@

<!-- flashcard_portrait.xml -->
<string name="type_answer_hint">Type answer</string>
<string name="show_answer">Show answer</string>
<string name="show_answer" maxLength="41">Show answer</string>
<string name="hide_answer">Hide answer</string>
<string name="ease_button_again">Again</string>
<string name="ease_button_hard">Hard</string>
<string name="ease_button_good">Good</string>
<string name="ease_button_again" maxLength="41">Again</string>
<string name="ease_button_hard" maxLength="41">Hard</string>
<string name="ease_button_good" maxLength="41">Good</string>
<string name="ease_button_easy">Easy</string>
<string name="menu_import">Import</string>
<string name="undo" maxLength="29" comment="When tapping on this text, the last action is undone.">Undo</string>
<string name="redo">Redo</string>
<string name="redo" maxLength="41">Redo</string>
<string name="undo_action_whiteboard_last_stroke" comment="One of the display patterns of 'Undo' item on the action menu in Reviewer. It is shown as the title of the item when the whiteboard (handwriting) feature is enabled and visible and has any strokes (handwritten lines)">Undo stroke</string>
<string name="move_all_to_deck">Move all to deck</string>
<string name="unbury">Unbury</string>
Expand All @@ -70,25 +70,25 @@
<string name="browse_cards">Browse cards</string>
<string name="edit_deck_description" comment="edit the deck description">Edit description</string>
<string name="menu_add" comment="A generic add button. Please inform us if you need more specific strings" maxLength="29">Add</string>
<string name="menu_add_note">Add note</string>
<string name="menu_add_note" maxLength="41">Add note</string>
<string name="menu_my_account" comment="Label of the window in which the user should enter their account. This text can't be found in AnkiDroid directly.">Sync account</string>
<string name="menu_dismiss_note">Hide / delete</string>
<string name="menu_bury_card">Bury card</string>
<string name="menu_bury_note">Bury note</string>
<string name="menu_suspend_card">Suspend card</string>
<string name="menu_suspend_note">Suspend note</string>
<string name="menu_bury">Bury</string>
<string name="menu_suspend">Suspend</string>
<string name="menu_delete_note">Delete note</string>
<string name="menu_flag">Flag</string>
<string name="menu_dismiss_note" maxLength="41">Hide / delete</string>
<string name="menu_bury_card" maxLength="41">Bury card</string>
<string name="menu_bury_note" maxLength="41">Bury note</string>
<string name="menu_suspend_card" maxLength="41">Suspend card</string>
<string name="menu_suspend_note" maxLength="41">Suspend note</string>
<string name="menu_bury" maxLength="41">Bury</string>
<string name="menu_suspend" maxLength="41">Suspend</string>
<string name="menu_delete_note" maxLength="41">Delete note</string>
<string name="menu_flag" maxLength="41">Flag</string>
<string name="rename_flag">Rename flags</string>
<string name="menu_flag_card">Flag card</string>
<string name="menu_edit_tags">Edit tags</string>
<string name="menu_edit_tags" maxLength="41">Edit tags</string>
<string name="delete_note_message">Really delete this note and all its cards?\n%s</string>
<string name="menu_search">Lookup in %1$s</string>
<string name="menu_mark_note">Mark note</string>
<string name="menu_mark_note" maxLength="41">Mark note</string>
<string name="menu_unmark_note">Unmark note</string>
<string name="menu_enable_voice_playback">Enable voice playback</string>
<string name="menu_enable_voice_playback" maxLength="41">Enable voice playback</string>
<string name="menu_disable_voice_playback">Disable voice playback</string>
<string name="new_deck">Create deck</string>
<string name="new_dynamic_deck">Create filtered deck</string>
Expand Down Expand Up @@ -149,7 +149,7 @@
<string name="card_template_browser_appearance_title">Browser appearance</string>

<!-- card Info -->
<string name="card_info_title">Card info</string>
<string name="card_info_title" maxLength="41">Card info</string>

<!-- Permissions -->
<string name="read_write_permission_label">Read and write to the AnkiDroid database</string>
Expand Down
28 changes: 14 additions & 14 deletions AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
<string name="updated_version">Updated to version %s</string>

<!-- Reviewer.kt -->
<string name="save_whiteboard">Save whiteboard</string>
<string name="enable_stylus">Enable stylus writing</string>
<string name="save_whiteboard" maxLength="41">Save whiteboard</string>
<string name="enable_stylus" maxLength="41">Enable stylus writing</string>
<string name="disable_stylus">Disable stylus writing</string>
<string name="enable_whiteboard">Enable whiteboard</string>
<string name="enable_whiteboard" maxLength="41">Enable whiteboard</string>
<string name="disable_whiteboard">Disable whiteboard</string>
<string name="show_whiteboard">Show whiteboard</string>
<string name="hide_whiteboard">Hide whiteboard</string>
<string name="clear_whiteboard">Clear whiteboard</string>
<string name="replay_audio">Replay audio</string>
<string name="hide_whiteboard" maxLength="41">Hide whiteboard</string>
<string name="clear_whiteboard" maxLength="41">Clear whiteboard</string>
<string name="replay_audio" maxLength="41">Replay audio</string>
<string name="leech_suspend_notification">Card marked as leech and suspended</string>
<string name="leech_notification">Card marked as leech</string>
<string name="webview_crash_unknown">Unknown error</string>
Expand All @@ -59,7 +59,7 @@
<string name="webview_crash_loop_dialog_title">System WebView Rendering Failure</string>
<string name="webview_crash_loop_dialog_content">System WebView failed to render card \'%1$s\'.\n %2$s</string>

<string name="filter_by_flags">Flags</string>
<string name="filter_by_flags" maxLength="41">Flags</string>

<!-- Custom study options -->
<string name="custom_study_increase_new_limit">Modify today’s new card limit</string>
Expand All @@ -74,7 +74,7 @@
</plurals>

<!-- Card editor -->
<string name="cardeditor_title_edit_card">Edit note</string>
<string name="cardeditor_title_edit_card" maxLength="41">Edit note</string>
<string name="discard">Discard</string>
<string name="note_editor_no_cards_created">No cards created. Please fill in more fields</string>
<string name="note_editor_no_cards_created_all_fields">The current note type did not produce any cards.\nPlease choose another note type, or click ‘Cards’ and add a field substitution</string>
Expand Down Expand Up @@ -153,9 +153,9 @@
<string name="export_choice_save_to">Save to</string>
<string name="export_saving_exported_collection">Saving exported file&#8230;</string>
<string name="study_options" comment="Name for a preference category in Filtered deck (aka Cram deck, aka Custom study) options" maxLength="29">Options</string>
<string name="menu__deck_options">Deck options</string>
<string name="menu__deck_options" maxLength="41">Deck options</string>
<string name="menu__study_options" comment="Menu item that opens options for a Filtered deck (aka Cram deck, aka Custom study)">Study options</string>
<string name="select_tts">Set TTS language</string>
<string name="select_tts" maxLength="41">Set TTS language</string>
<string name="custom_study">Custom study</string>
<string name="more_options">More</string>
<string name="dyn_deck_desc">This is a special deck for studying outside of the normal schedule. Cards will be automatically returned to their original decks after you review them. Deleting this deck from the deck list will return all remaining cards to their original deck.</string>
Expand All @@ -179,8 +179,8 @@
<string name="web_page_error">Error loading page: %s</string>
<!-- The name of the deck which corrupt cards will be moved to -->
<!-- Deckpicker Background -->
<string name="background_image_title">Background</string>
<string name="choose_an_image">Select image</string>
<string name="background_image_title" maxLength="41">Background</string>
<string name="choose_an_image" maxLength="41">Select image</string>
<string name="remove_background_image">Remove background?</string>
<!-- Card Template Browser Appearance -->
<string name="restore_default">Restore Default</string>
Expand All @@ -191,8 +191,8 @@
<string name="white_board_image_save_failed">Failed to save whiteboard image. %s</string>
<string name="white_board_image_saved">Whiteboard image saved to %s</string>

<string name="title_whiteboard_pen_color">Whiteboard pen color</string>
<string name="title_whiteboard_editor">Whiteboard editor</string>
<string name="title_whiteboard_pen_color" maxLength="41">Whiteboard pen color</string>
<string name="title_whiteboard_editor" maxLength="41">Whiteboard editor</string>

<string name="user_is_a_robot">Detected automated test. If you are a human, contact AnkiDroid support</string>

Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<!-- scoped storage -->
<string name="backup_your_collection">Backup your collection</string>
<string name="backup_collection_message">You haven\'t backed up your collection in a while. You should do this now to prevent data loss</string>
<string name="button_backup">Backup</string>
<string name="button_backup" maxLength="41">Backup</string>
<string name="button_disable_reminder">Disable reminder</string>
<string name="button_backup_later" comment="dismiss the 'Backup' dialog for around 2 weeks">Later</string>
<string name="button_do_not_show_again" comment="permanently dismisses a dialog">Don\'t show again</string>
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/04-network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!-- Please run ‘Check database’ before syncing -->
<string name="sync_sanity_local">Local</string>
<string name="sync_sanity_remote">Remote</string>
<string name="one_way_sync_title">One-way sync</string>
<string name="one_way_sync_title" maxLength="41">One-way sync</string>
<string name="one_way_sync_confirmation">One way sync requested</string>
<string name="full_sync_confirmation">The requested change will require a full upload of the database when you next synchronize your collection. If you have reviews or other changes waiting on another device that haven’t been synchronized here yet, they will be lost. Continue?</string>
<string name="full_sync_confirmation_upgrade">Due to a bug in the previously installed version of AnkiDroid, it’s recommended to force a full sync.</string>
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/05-feedback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<resources>
<!-- Feedback.java -->
<string name="empty_string"/>
<string name="error_reporting_choice">Error reporting mode</string>
<string name="error_reporting_choice" maxLength="41">Error reporting mode</string>
<string name="feedback_disclaimer">Disclaimer: We don’t collect any personal information such as your email address, phone number, or your phone IMEI. We do collect some information about your device such as the manufacturer, model and version of Android, as well as the nature of reported errors themselves and the steps which led up to them occurring.</string>
<string name="feedback_title">AnkiDroid Feedback</string>
<string name="feedback_default_text">Enter your feedback or information about the nature of any errors you’re reporting.</string>
Expand Down
12 changes: 4 additions & 8 deletions AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,10 @@ this formatter is used if the bind only applies to both the question and the ans
<br><br>
You can restore from a backup and export your collection in the deck list menu.
]]></string>
<string name="pref__minutes_between_automatic_backups__title" maxLength="41"
>Minutes between automatic backups</string>
<string name="pref__daily_backups_to_keep__title" maxLength="41"
>Daily backups to keep</string>
<string name="pref__weekly_backups_to_keep__title" maxLength="41"
>Weekly backups to keep</string>
<string name="pref__monthly_backups_to_keep__title" maxLength="41"
>Monthly backups to keep</string>
<string name="pref__minutes_between_automatic_backups__title" maxLength="41">Minutes between automatic backups</string>
<string name="pref__daily_backups_to_keep__title" maxLength="41">Daily backups to keep</string>
<string name="pref__weekly_backups_to_keep__title" maxLength="41">Weekly backups to keep</string>
<string name="pref__monthly_backups_to_keep__title" maxLength="41">Monthly backups to keep</string>

<!-- #######################################################################################
################################# Manage space activity ###############################
Expand Down
46 changes: 23 additions & 23 deletions AnkiDroid/src/main/res/values/11-arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@
<string name="html_size_code_xx_large">xx-large</string>

<!-- gestures_labels -->
<string name="answer_again">Answer again</string>
<string name="answer_hard">Answer hard</string>
<string name="answer_good">Answer good</string>
<string name="answer_easy">Answer easy</string>
<string name="gesture_play">Play media</string>
<string name="gesture_abort_learning">Close reviewer</string>
<string name="gesture_flag_red">Toggle Red Flag</string>
<string name="gesture_flag_orange">Toggle Orange Flag</string>
<string name="gesture_flag_green">Toggle Green Flag</string>
<string name="gesture_flag_blue">Toggle Blue Flag</string>
<string name="gesture_flag_pink">Toggle Pink Flag</string>
<string name="gesture_flag_turquoise">Toggle Turquoise Flag</string>
<string name="gesture_flag_purple">Toggle Purple Flag</string>
<string name="gesture_flag_remove">Remove Flag</string>
<string name="gesture_page_up">Page Up</string>
<string name="gesture_page_down">Page Down</string>
<string name="gesture_abort_sync">Close reviewer and Sync</string>
<string name="gesture_toggle_whiteboard">Toggle Whiteboard</string>
<string name="gesture_show_hint">Show Hint</string>
<string name="gesture_show_all_hints">Show All Hints</string>
<string name="record_voice">Record Voice</string>
<string name="replay_voice">Replay Voice</string>
<string name="save_voice">Save Recording</string>
<string name="answer_again" maxLength="41">Answer again</string>
<string name="answer_hard" maxLength="41">Answer hard</string>
<string name="answer_good" maxLength="41">Answer good</string>
<string name="answer_easy" maxLength="41">Answer easy</string>
<string name="gesture_play" maxLength="41">Play media</string>
<string name="gesture_abort_learning" maxLength="41">Close reviewer</string>
<string name="gesture_flag_red" maxLength="41">Toggle Red Flag</string>
<string name="gesture_flag_orange" maxLength="41">Toggle Orange Flag</string>
<string name="gesture_flag_green" maxLength="41">Toggle Green Flag</string>
<string name="gesture_flag_blue" maxLength="41">Toggle Blue Flag</string>
<string name="gesture_flag_pink" maxLength="41">Toggle Pink Flag</string>
<string name="gesture_flag_turquoise" maxLength="41">Toggle Turquoise Flag</string>
<string name="gesture_flag_purple" maxLength="41">Toggle Purple Flag</string>
<string name="gesture_flag_remove" maxLength="41">Remove Flag</string>
<string name="gesture_page_up" maxLength="41">Page Up</string>
<string name="gesture_page_down" maxLength="41">Page Down</string>
<string name="gesture_abort_sync" maxLength="41">Close reviewer and Sync</string>
<string name="gesture_toggle_whiteboard" maxLength="41">Toggle Whiteboard</string>
<string name="gesture_show_hint" maxLength="41">Show Hint</string>
<string name="gesture_show_all_hints" maxLength="41">Show All Hints</string>
<string name="record_voice" maxLength="41">Record Voice</string>
<string name="replay_voice" maxLength="41">Replay Voice</string>
<string name="save_voice" maxLength="41">Save Recording</string>

</resources>
4 changes: 2 additions & 2 deletions lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class IssueRegistry : IssueRegistry() {
PrintStackTraceUsage.ISSUE,
NonPositionalFormatSubstitutions.ISSUE,
TranslationTypo.ISSUE,
FixedPreferencesTitleLength.ISSUE_MAX_LENGTH,
FixedPreferencesTitleLength.ISSUE_TITLE_LENGTH,
FixedPreferencesTitleLength.PREFERENCES_ISSUE_MAX_LENGTH,
FixedPreferencesTitleLength.PREFERENCES_ISSUE_TITLE_LENGTH,
VariableNamingDetector.ISSUE,
InvalidStringFormatDetector.ISSUE,
AvoidAlertDialogUsage.ISSUE
Expand Down
Loading

0 comments on commit 197b2bc

Please sign in to comment.