Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom linter for i18n/label translation keywords #17610

Merged
merged 6 commits into from
Oct 11, 2023

Conversation

ilmotta
Copy link
Contributor

@ilmotta ilmotta commented Oct 10, 2023

Summary

Have you ever made a comment about the guideline: "Please, qualify translation keywords with :t" in calls to i18n/label, or something like that? I assure you this kind of comment has been made numerous times!

What if we could lint and automate this verification? Of course we can, with the help of Clojure's linter, clj-kondo.

In this PR I'm adding a custom linter to verify i18n/label is called with a qualified keyword, like :t/foo. I chose to implement this simple linter to avoid increasing the scope of this PR, but the sky is the limit 🛸

And?

I hope this PR sets the stage for other devs to consider more and more lint automation instead of manually reviewing conventions in PRs.

If you want to understand how to write custom linters, check out https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md. You can fire the Clojure JVM REPL in status-mobile and play with the clj-kondo hook too, it works beautifully.

Why do we care about this rule?

By making sure all translation keywords are qualified with :t, it is trivial to grep or replace them because they're unique in the repo, and can't be confused with other words if you search by :t/<something>.

Notes

It's a best practice to commit clj-kondo configuration from external libs in the .clj-kondo directory. The directory .clj-kondo/babashka is auto-generated, that's why I added it.

Screenshots

I didn't check Vim or IntelliJ, but I'm sure they work just as well with no extra configuration on your part. Just remember to restart the language server or to delete the clj-kondo/.cache directory if you're not seeing errors in the editor for this new linter.

Emacs:

VS Code:

Areas that may be impacted

None, safe keyword updates.

Steps to test

For developers only: remove the :t qualification in any translation keyword passed to utils.i18n/label. Then check the output of make lint and the flagged error in your editor.

status: ready

@ilmotta ilmotta added the linting Linter settings & improvements label Oct 10, 2023
@ilmotta ilmotta self-assigned this Oct 10, 2023
@ilmotta ilmotta requested a review from jakubgs as a code owner October 10, 2023 20:08
@@ -0,0 +1,25 @@
(ns hooks.core
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this is the namespace that matters for this PR.

@status-im-auto
Copy link
Member

status-im-auto commented Oct 10, 2023

Jenkins Builds

Click to see older builds (4)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ c2cb287 #2 2023-10-10 20:18:08 ~5 min android-e2e 🤖apk 📲
✔️ c2cb287 #2 2023-10-10 20:18:26 ~5 min android 🤖apk 📲
✔️ c2cb287 #2 2023-10-10 20:21:14 ~8 min ios 📱ipa 📲
✔️ c2cb287 #2 2023-10-10 20:21:37 ~8 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 37db916 #3 2023-10-11 14:14:48 ~5 min android-e2e 🤖apk 📲
✔️ 37db916 #3 2023-10-11 14:16:44 ~7 min android 🤖apk 📲
✔️ 37db916 #3 2023-10-11 14:18:12 ~8 min ios 📱ipa 📲
✔️ 37db916 #3 2023-10-11 14:19:13 ~9 min tests 📄log
✔️ 9db641f #4 2023-10-11 21:39:34 ~9 min android 🤖apk 📲
✔️ 9db641f #4 2023-10-11 21:39:52 ~9 min android-e2e 🤖apk 📲
✔️ 9db641f #4 2023-10-11 21:40:40 ~10 min tests 📄log
✔️ 9db641f #4 2023-10-11 21:47:57 ~17 min ios 📱ipa 📲

@flexsurfer
Copy link
Member

hey @ilmotta awesome work, do you think it will be possible to analyze en.json, and show the info about, unused keys and absent keys in en.json? thanks

Copy link
Member

@flexsurfer flexsurfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@status-im-auto
Copy link
Member

84% of end-end tests have passed

Total executed tests: 43
Failed tests: 7
Passed tests: 36
IDs of failed tests: 702732,703495,702745,702786,702844,702731,702808 

Failed tests (7)

Click to expand
  • Rerun failed tests

  • Class TestCommunityMultipleDeviceMerged:

    1. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844

    Device 2: Tap on found: SendMessageButton
    Device 1: Getting preview message for link: https://youtu.be/Je7yErjEVt4

    critical/chats/test_public_chat_browsing.py:568: in test_community_links_with_previews_github_youtube_twitter_gif_send_enable
        message.wait_for_element(60)
    ../views/base_element.py:121: in wait_for_element
        raise TimeoutException(
     Device `1`: `PreviewMessage` by` xpath`: `//*[starts-with(@text,'https://youtu.be/Je7yErjEVt4')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']` is not found on the screen after wait_for_element
    



    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745

    Device 2: Find MemberPhoto by xpath: //*[starts-with(@text,'profile_photo')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']//*[@content-desc='user-avatar']
    Device 2: Image differs from template to 7.598924823835784 percents

    critical/chats/test_1_1_public_chats.py:312: in test_1_1_chat_non_latin_messages_stack_update_profile_photo
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Image of user in 1-1 chat is too different from template!
    



    Device sessions

    2. test_1_1_chat_pin_messages, id: 702731

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Pin feature is in development]]

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_mentions_push_notification, id: 702786

    Device 2: Getting PN by 'user_2'
    Device 2: Looking for a message by text: user_2

    critical/chats/test_public_chat_browsing.py:874: in test_community_mentions_push_notification
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Can not edit a message with a mention
    



    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Pin feature is in development]]

    2. test_group_chat_mute_chat, id: 703495

    Device 2: Click until ChatMessageInput by accessibility id: chat-message-input will be presented
    Device 2: Looking for a message by text: Chat is unmuted now

    critical/chats/test_group_chat.py:473: in test_group_chat_mute_chat
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     New messages counter near chats tab button is 1 after unmute, but should be 2
    



    Device sessions

    3. test_group_chat_offline_pn, id: 702808

    Device 3: Looking for a message by text: message from old member
    Device 3: Looking for a message by text: message from new member

    critical/chats/test_group_chat.py:309: in test_group_chat_offline_pn
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Messages PN was not fetched from offline 
    

    [[Data delivery issue]]

    Device sessions

    Passed tests (36)

    Click to expand

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    3. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    3. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    4. test_1_1_chat_edit_message, id: 702855
    Device sessions

    5. test_1_1_chat_send_image_save_and_share, id: 703391
    Device sessions

    6. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    3. test_community_discovery, id: 703503
    Device sessions

    4. test_community_undo_delete_message, id: 702869
    Device sessions

    5. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    6. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    2. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    6. test_community_message_delete, id: 702839
    Device sessions

    7. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    8. test_community_message_edit, id: 702843
    Device sessions

    9. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_hashtag_links_to_community_channels, id: 702948
    Device sessions

    3. test_community_leave, id: 702845
    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    2. test_group_chat_reactions, id: 703202
    Device sessions

    3. test_group_chat_join_send_text_messages_push, id: 702807
    Device sessions

    Copy link
    Member

    @smohamedjavid smohamedjavid left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Great work! 🚀

    @ilmotta
    Copy link
    Contributor Author

    ilmotta commented Oct 11, 2023

    hey @ilmotta awesome work, do you think it will be possible to analyze en.json, and show the info about, unused keys and absent keys in en.json? thanks

    Thanks @flexsurfer. It's theoretically possible because clj-kondo has a project-wide analyzer, different than the solution I used here for linting purposes. We can explore your idea I'm sure.

    @ilmotta ilmotta force-pushed the ilmotta/add-custom-status-linter branch from c2cb287 to 37db916 Compare October 11, 2023 14:09
    Copy link
    Contributor

    @ajayesivan ajayesivan left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Excellent!

    Copy link
    Member

    @briansztamfater briansztamfater left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Love this!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    linting Linter settings & improvements
    Projects
    Archived in project
    Archived in project
    Development

    Successfully merging this pull request may close these issues.