make clj-kondo hook's name match the fully qualified name of the symbol it's linting (#17817)

This commit is contained in:
Dmitri Akatov 2023-11-07 06:10:36 +00:00 committed by GitHub
parent a6d7502455
commit 1755780950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 20 deletions

View File

@ -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}}}

View File

@ -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)")}))

View File

@ -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)")})
)