Skip to content

Commit f733ff1

Browse files
authored
Merge pull request #33 from lambdaisland/laurence/improve-clj-kondo-hook
Laurence/improve clj kondo hook
2 parents 235299f + 0e6ef5c commit f733ff1

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

.clj-kondo/config.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{:lint-as {lambdaisland.ornament/defprop clojure.core/def
22
lambdaisland.ornament/defrules clojure.core/def}
3-
:hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}}}
3+
:hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}}
4+
:linters {:lambdaisland.ornament/invalid-syntax
5+
{:level :warning}}}

.clj-kondo/hooks/ornament.clj

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,40 @@
1313
_ (when-not (api/keyword-node? html-tag)
1414
(api/reg-finding! {:row (:row (meta html-tag))
1515
:col (:col (meta html-tag))
16-
:message "Html-tag must be a keyword"
16+
:message "Tag must be a keyword or an ornament-styled-component"
1717
:type :lambdaisland.ornament/invalid-syntax}))
1818
; _ (prn :html-tag html-tag)
1919
; _ (prn :more more)
2020
fn-tag (first (drop-while (fn [x]
21-
(or (api/keyword-node? x)
21+
(or (api/string-node? x)
22+
(api/keyword-node? x)
2223
(api/map-node? x)
2324
(api/vector-node? x)))
2425
more))
25-
_ (prn :fn-tag fn-tag)
26-
_ (when (or (api/list-node? fn-tag)
27-
(nil? fn-tag))
26+
; _ (prn :fn-tag fn-tag)
27+
_ (when (and fn-tag
28+
(not (api/list-node? fn-tag)))
2829
(api/reg-finding! {:row (:row (meta fn-tag))
2930
:col (:col (meta fn-tag))
30-
:message "fn-tag must be at least a list or nil"
31-
:type :lambdaisland.ornament/invalid-syntax}))
32-
def-class-form (api/list-node
33-
(list (api/token-node 'def)
34-
class-name
35-
(api/token-node 'nil)))]
31+
:message "Function part (if present) must be a list"
32+
:type :lambdaisland.ornament/invalid-syntax}))]
3633
(if (api/list-node? fn-tag)
3734
(let [[binding-vec & body] (:children fn-tag)
38-
new-node (api/list-node
39-
(list*
40-
(api/token-node 'fn)
41-
binding-vec
42-
body))]
43-
(prn :new-node (api/sexpr new-node))
44-
{:node new-node})
35+
fn-node (api/list-node
36+
(list*
37+
(api/token-node 'fn)
38+
binding-vec
39+
body))
40+
new-def-node (api/list-node
41+
(list (api/token-node 'def)
42+
class-name
43+
fn-node))]
44+
(prn :new-def-node (api/sexpr new-def-node))
45+
{:node new-def-node})
4546
;; nil node
46-
{:node def-class-form})))
47+
(let [def-class-form (api/list-node
48+
(list (api/token-node 'def)
49+
class-name
50+
(api/token-node 'nil)))]
51+
(prn :def-class-form (api/sexpr def-class-form))
52+
{:node def-class-form}))))

0 commit comments

Comments
 (0)