make clj-kondo hook's name match the fully qualified name of the symbol it's linting (#17817)
This commit is contained in:
parent
a6d7502455
commit
1755780950
|
@ -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}}}
|
:linters {:status-im.linter/invalid-translation-keyword {:level :error}}}
|
||||||
|
|
|
@ -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)")}))
|
|
|
@ -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)")})
|
||||||
|
)
|
Loading…
Reference in New Issue