-
Notifications
You must be signed in to change notification settings - Fork 985
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
Conversation
@@ -0,0 +1,25 @@ | |||
(ns hooks.core |
There was a problem hiding this comment.
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.
Jenkins BuildsClick to see older builds (4)
|
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
84% of end-end tests have passed
Failed tests (7)Click to expandClass TestCommunityMultipleDeviceMerged:
Class TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityMultipleDeviceMergedTwo:
Class TestGroupChatMultipleDeviceMergedNewUI:
Passed tests (36)Click to expandClass TestOneToOneChatMultipleSharedDevicesNewUiTwo:
Class TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestActivityMultipleDevicePR:
Class TestCommunityOneDeviceMerged:
Class TestActivityMultipleDevicePRTwo:
Class TestActivityCenterContactRequestMultipleDevicePR:
Class TestCommunityMultipleDeviceMerged:
Class TestCommunityMultipleDeviceMergedTwo:
Class TestGroupChatMultipleDeviceMergedNewUI:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 🚀
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. |
c2cb287
to
37db916
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!
37db916
to
9db641f
Compare
Summary
Have you ever made a comment about the guideline: "Please, qualify translation keywords with
:t
" in calls toi18n/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 toutils.i18n/label
. Then check the output ofmake lint
and the flagged error in your editor.status: ready