diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-09-24 21:57:57 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-09-24 21:57:57 +0300 |
| commit | d98e13761fdcaa8cba912d367670855087b29c01 (patch) | |
| tree | 878ae923514b95168b6943be4a8ee7dbee1d81a6 /resources/clj-kondo/hooks/dompa.clj | |
| parent | 13f7093cfc9860dc2a9b2fd94f19d3661f15b3d3 (diff) | |
Improve $ macro clj-kondo hook, impl fragment node (well, not really a node itself, but any node with a name of :<> will replace itself with its children.
Diffstat (limited to 'resources/clj-kondo/hooks/dompa.clj')
| -rw-r--r-- | resources/clj-kondo/hooks/dompa.clj | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/resources/clj-kondo/hooks/dompa.clj b/resources/clj-kondo/hooks/dompa.clj index 2433051..31ab3d3 100644 --- a/resources/clj-kondo/hooks/dompa.clj +++ b/resources/clj-kondo/hooks/dompa.clj @@ -1,7 +1,7 @@ (ns hooks.dompa (:require [clj-kondo.hooks-api :as api])) -(defn string-like? [x] +(defn str-able? [x] (or (api/string-node? x) (api/token-node? x))) @@ -13,7 +13,7 @@ ; strings, i.e. whatever (str) can do. (or (api/string-node? first-arg) (api/token-node? first-arg)) - (let [invalid-args (filter #(not (string-like? %)) rest-args)] + (let [invalid-args (filter #(not (str-able? %)) rest-args)] (doall (for [invalid-arg invalid-args] (api/reg-finding! @@ -34,7 +34,16 @@ "the second argument must be a sequence or a map. " "In other words, the second argument must be an attribute map " "or sequence of other nodes created with the $ macro.") - :type :dompa.utils/$-arg-validation))))) + :type :dompa.utils/$-arg-validation)) - ; if the first arg is a keyword, the second arg is a map, then the third arg can - ; only be a sequence + ; if the first arg is a keyword, the second arg is a map, then from + ; the second forwards everything has to be a list node + (and (api/keyword-node? first-arg) + (api/map-node? (first rest-args)) + (not (every? #(api/list-node? %) (rest rest-args)))) + (api/reg-finding! + (assoc (meta (second rest-args)) + :message (str "Invalid argument type. When having a attribute map, " + "the rest of the arguments must be a $ macro or a sequence " + "of $ macros") + :type :dompa.utils/$-arg-validation))))) |
