|
| 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