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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clj-kondo/babashka/fs/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {babashka.fs/with-temp-dir clojure.core/let}}
1 change: 1 addition & 0 deletions .clj-kondo/babashka/sci/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:hooks {:macroexpand {sci.core/copy-ns sci.core/copy-ns}}}
9 changes: 9 additions & 0 deletions .clj-kondo/babashka/sci/sci/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns sci.core)

(defmacro copy-ns
([ns-sym sci-ns]
`(copy-ns ~ns-sym ~sci-ns nil))
([ns-sym sci-ns opts]
`[(quote ~ns-sym)
~sci-ns
(quote ~opts)]))
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{:lint-as {status-im.utils.views/defview clojure.core/defn
{:config-paths ["status-im"]
:lint-as {status-im.utils.views/defview clojure.core/defn
status-im.utils.views/letsubs clojure.core/let
reagent.core/with-let clojure.core/let
status-im.utils.fx/defn clj-kondo.lint-as/def-catch-all
Expand Down
2 changes: 2 additions & 0 deletions .clj-kondo/status-im/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:hooks {:analyze-call {utils.i18n/label hooks.core/i18n-label}}
:linters {:status-im.linter/invalid-translation-keyword {:level :error}}}
19 changes: 19 additions & 0 deletions .clj-kondo/status-im/hooks/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(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.

(:require [clj-kondo.hooks-api :as api]))

(defn i18n-label
"Verify call to `i18n/label` pass the translation keyword qualified with `t`."
[{:keys [node]}]
(let [[_ translation-key-node & _] (:children node)]
(when (and (api/keyword-node? translation-key-node)
(not= "t" (-> translation-key-node api/sexpr namespace)))
(api/reg-finding! (assoc (meta translation-key-node)
:message "Translation keyword should be qualified with \"t\""
:type :status-im.linter/invalid-translation-keyword)))))

(comment
;; Valid
(i18n-label {:node (api/parse-string "(i18n/label :t/foo)")})

;; Invalid
(i18n-label {:node (api/parse-string "(i18n/label :foo)")}))
Loading