diff options
| -rw-r--r-- | .clj-kondo/config.edn | 1 | ||||
| -rw-r--r-- | deps.edn | 4 | ||||
| -rw-r--r-- | resources/clj-kondo/config.edn | 7 | ||||
| -rw-r--r-- | resources/clj-kondo/hooks/dompa.clj | 27 | ||||
| -rw-r--r-- | src/dompa/templates.cljc | 1 |
5 files changed, 35 insertions, 5 deletions
diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 0000000..9dfe1d2 --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1 @@ +{:config-paths ["../resources/clj-kondo"]}
\ No newline at end of file @@ -1,3 +1,3 @@ -{:deps {} +{:deps {org.clojure/clojure {:mvn/version "1.12.2"}} :paths ["src" "resources/clj-kondo"] - :aliases {:dev {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2025.07.28"}}}}}
\ No newline at end of file + :aliases {:dev {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2025.09.22"}}}}}
\ No newline at end of file diff --git a/resources/clj-kondo/config.edn b/resources/clj-kondo/config.edn index 813976f..1a76557 100644 --- a/resources/clj-kondo/config.edn +++ b/resources/clj-kondo/config.edn @@ -1,2 +1,5 @@ -{:hooks {:analyze-call {dompa.templates/$ hooks.dompa/$}} - :linters {:dompa.templates/$-arg-validation {:level :warning}}}
\ No newline at end of file +{:hooks {:analyze-call {dompa.templates/$ hooks.dompa/$ + dompa.templates/defhtml hooks.dompa/defhtml}} + :linters {:dompa.templates/$-arg-validation {:level :warning} + :dompa.templates/defhtml-arg-validation {:level :warning}} + :lint-as {dompa.templates/defhtml clojure.core/defn}}
\ No newline at end of file diff --git a/resources/clj-kondo/hooks/dompa.clj b/resources/clj-kondo/hooks/dompa.clj index 5e36df6..a5c802f 100644 --- a/resources/clj-kondo/hooks/dompa.clj +++ b/resources/clj-kondo/hooks/dompa.clj @@ -57,3 +57,30 @@ :message (str "Invalid argument type. Argument must be a $ macro " "or a sequence of $ macros.") :type :dompa.templates/$-arg-validation))))) + +(defn defhtml [{:keys [node]}] + (let [[_ first-arg second-arg & rest-args] (:children node)] + (cond + ; first argument has to be a symbol + (not (api/token-node? first-arg)) + (api/reg-finding! + (assoc (meta first-arg) + :message "Invalid argument type. Binding name must be a symbol." + :type :dompa.templates/defhtml-arg-validation)) + + ; second argument should be a vector + (not (api/vector-node? second-arg)) + (api/reg-finding! + (assoc (meta second-arg) + :message "Invalid argument type. Must be a vector of arguments." + :type :dompa.templates/defhtml-arg-validation)) + + ; rest of the arguments should be a list + (not (every? #(api/list-node? %) rest-args)) + (doall + (for [arg rest-args] + (api/reg-finding! + (assoc (meta arg) + :message (str "Invalid argument type. Argument must be a $ macro " + "or a sequence of $ macros.")))))))) + diff --git a/src/dompa/templates.cljc b/src/dompa/templates.cljc index 8a7aae9..21ce8f9 100644 --- a/src/dompa/templates.cljc +++ b/src/dompa/templates.cljc @@ -2,7 +2,6 @@ (:require [dompa.nodes :as nodes])) (defmacro defhtml - {:clj-kondo/lint-as 'clojure.core/defn} [name & args-and-elements] (let [[args & elements] args-and-elements] `(defn ~name ~args |
