Skip to content

Commit

Permalink
make clj-kondo hook's name match the fully qualified name of the symb…
Browse files Browse the repository at this point in the history
…ol it's linting (#17817)
  • Loading branch information
akatov authored Nov 7, 2023
1 parent a6d7502 commit 1755780
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .clj-kondo/status-im/config.edn
Original file line number Diff line number Diff line change
@@ -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}}}
19 changes: 0 additions & 19 deletions .clj-kondo/status-im/hooks/core.clj

This file was deleted.

26 changes: 26 additions & 0 deletions .clj-kondo/status-im/utils/i18n.clj
Original file line number Diff line number Diff line change
@@ -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)")})
)

0 comments on commit 1755780

Please sign in to comment.