Skip to content

Commit 240b3bf

Browse files
committed
clj-kondo config to make ornament components play nice with linting
1 parent ca7862f commit 240b3bf

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.clj-kondo/config.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:lint-as {lambdaisland.ornament/defprop clojure.core/def
2+
lambdaisland.ornament/defrules clojure.core/def}
3+
:hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}}}

.clj-kondo/hooks/ornament.clj

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(ns hooks.ornament
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn defstyled [{:keys [node]}]
5+
(let [[class-name html-tag & more] (rest (:children node))
6+
_ (when-not (and (api/token-node? class-name)
7+
(simple-symbol? (api/sexpr class-name)))
8+
(api/reg-finding! {:row (:row (meta class-name))
9+
:col (:col (meta class-name))
10+
:message "Style name must be a symbol"
11+
:type :lambdaisland.ornament/invalid-syntax}))
12+
; _ (prn :class-name class-name)
13+
_ (when-not (api/keyword-node? html-tag)
14+
(api/reg-finding! {:row (:row (meta html-tag))
15+
:col (:col (meta html-tag))
16+
:message "Html-tag must be a keyword"
17+
:type :lambdaisland.ornament/invalid-syntax}))
18+
; _ (prn :html-tag html-tag)
19+
; _ (prn :more more)
20+
fn-tag (first (drop-while (fn [x]
21+
(or (api/keyword-node? x)
22+
(api/map-node? x)
23+
(api/vector-node? x)))
24+
more))
25+
_ (prn :fn-tag fn-tag)
26+
_ (when (or (api/list-node? fn-tag)
27+
(nil? fn-tag))
28+
(api/reg-finding! {:row (:row (meta fn-tag))
29+
:col (:col (meta fn-tag))
30+
:message "fn-tag must be at least a list or nil"
31+
:type :lambdaisland.ornament/invalid-syntax}))]
32+
(if (api/list-node? fn-tag)
33+
(let [[binding-vec & body] (:children fn-tag)
34+
new-node (api/list-node
35+
(list*
36+
(api/token-node 'fn)
37+
binding-vec
38+
body))]
39+
(prn :new-node (api/sexpr new-node))
40+
{:node new-node})
41+
;; nil node
42+
{:node true})))

0 commit comments

Comments
 (0)