diff --git a/.clj-kondo/status-im/config.edn b/.clj-kondo/status-im/config.edn index eb6f89e6f4..217e6f759e 100644 --- a/.clj-kondo/status-im/config.edn +++ b/.clj-kondo/status-im/config.edn @@ -1,2 +1,2 @@ -{:hooks {:analyze-call {utils.i18n/label hooks.core/i18n-label}} +{:hooks {:analyze-call {utils.i18n/label utils.i18n/label}} :linters {:status-im.linter/invalid-translation-keyword {:level :error}}} diff --git a/.clj-kondo/status-im/hooks/core.clj b/.clj-kondo/status-im/hooks/core.clj deleted file mode 100644 index 872bd3977c..0000000000 --- a/.clj-kondo/status-im/hooks/core.clj +++ /dev/null @@ -1,19 +0,0 @@ -(ns hooks.core - (: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)")})) diff --git a/.clj-kondo/status-im/utils/i18n.clj b/.clj-kondo/status-im/utils/i18n.clj new file mode 100644 index 0000000000..bde1603bae --- /dev/null +++ b/.clj-kondo/status-im/utils/i18n.clj @@ -0,0 +1,26 @@ +(ns utils.i18n + (:require [clj-kondo.hooks-api :as hooks])) + +(defn label + "Verify call to `utils.i18n/label` pass the translation keyword qualified with `t`." + [{:keys [node]}] + (let [[_ translation-key-node & _] (:children node)] + (when (and (hooks/keyword-node? translation-key-node) + (not= "t" (-> translation-key-node hooks/sexpr namespace))) + (hooks/reg-finding! (assoc (meta translation-key-node) + :message "Translation keyword should be qualified with \"t\"" + :type :status-im.linter/invalid-translation-keyword))))) + +(comment + ;; Valid + (label {:node (hooks/parse-string "(i18n/label :t/foo {:var \"hello\"})") + :cljc false + :lang :cljs + :filename "" + :config {} + :ns "" + :context nil}) + + ;; Invalid + (label {:node (hooks/parse-string "(i18n/label :foo)")}) +)