From d98e13761fdcaa8cba912d367670855087b29c01 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Wed, 24 Sep 2025 21:57:57 +0300 Subject: 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. --- resources/clj-kondo/hooks/dompa.clj | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'resources/clj-kondo') 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))))) -- cgit v1.2.3