From 6b18b47cab905cb5e66c5f8d5ed0fde0450d10e2 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Sat, 6 Dec 2025 03:12:25 +0800 Subject: [PATCH 1/2] fix the bug of .clj-kondo/hooks/ornament when defstyled has Fn part --- .clj-kondo/hooks/ornament.clj | 39 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/.clj-kondo/hooks/ornament.clj b/.clj-kondo/hooks/ornament.clj index a8a9c7e..115ad54 100644 --- a/.clj-kondo/hooks/ornament.clj +++ b/.clj-kondo/hooks/ornament.clj @@ -22,25 +22,30 @@ (api/map-node? x) (api/vector-node? x))) more)) - _ (prn :fn-tag fn-tag) - _ (when (or (api/list-node? fn-tag) - (nil? fn-tag)) + ; _ (prn :fn-tag fn-tag) + _ (when (and fn-tag + (not (api/list-node? fn-tag))) (api/reg-finding! {:row (:row (meta fn-tag)) :col (:col (meta fn-tag)) - :message "fn-tag must be at least a list or nil" - :type :lambdaisland.ornament/invalid-syntax})) - def-class-form (api/list-node - (list (api/token-node 'def) - class-name - (api/token-node 'nil)))] + :message "Function part (if present) must be a list" + :type :lambdaisland.ornament/invalid-syntax}))] (if (api/list-node? fn-tag) (let [[binding-vec & body] (:children fn-tag) - new-node (api/list-node - (list* - (api/token-node 'fn) - binding-vec - body))] - (prn :new-node (api/sexpr new-node)) - {:node new-node}) + fn-node (api/list-node + (list* + (api/token-node 'fn) + binding-vec + body)) + new-def-node (api/list-node + (list (api/token-node 'def) + class-name + fn-node))] + (prn :new-def-node (api/sexpr new-def-node)) + {:node new-def-node}) ;; nil node - {:node def-class-form}))) + (let [def-class-form (api/list-node + (list (api/token-node 'def) + class-name + (api/token-node 'nil)))] + (prn :def-class-form (api/sexpr def-class-form)) + {:node def-class-form})))) From 0e6ef5c0167cad48fb1081eb3c89e21ff6eca519 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Sat, 6 Dec 2025 03:49:39 +0800 Subject: [PATCH 2/2] enable the .clj-kondo warnings for ornament-invalid-syntax --- .clj-kondo/config.edn | 4 +++- .clj-kondo/hooks/ornament.clj | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 4585c52..548c6e6 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1,3 +1,5 @@ {:lint-as {lambdaisland.ornament/defprop clojure.core/def lambdaisland.ornament/defrules clojure.core/def} - :hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}}} + :hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}} + :linters {:lambdaisland.ornament/invalid-syntax + {:level :warning}}} diff --git a/.clj-kondo/hooks/ornament.clj b/.clj-kondo/hooks/ornament.clj index 115ad54..5cf30b0 100644 --- a/.clj-kondo/hooks/ornament.clj +++ b/.clj-kondo/hooks/ornament.clj @@ -13,12 +13,13 @@ _ (when-not (api/keyword-node? html-tag) (api/reg-finding! {:row (:row (meta html-tag)) :col (:col (meta html-tag)) - :message "Html-tag must be a keyword" + :message "Tag must be a keyword or an ornament-styled-component" :type :lambdaisland.ornament/invalid-syntax})) ; _ (prn :html-tag html-tag) ; _ (prn :more more) fn-tag (first (drop-while (fn [x] - (or (api/keyword-node? x) + (or (api/string-node? x) + (api/keyword-node? x) (api/map-node? x) (api/vector-node? x))) more))