diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-09-26 14:05:03 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-09-26 14:05:03 +0300 |
| commit | ea8dea2dd173c2e899640acae7d27e7e95b585f7 (patch) | |
| tree | f4894e9e89f88549aa7cde0b242431ecd6753450 /resources | |
| parent | 0392db96028d0b0a371396444d002eed15719771 (diff) | |
Improve clj-kondo hooks.
Diffstat (limited to 'resources')
| -rw-r--r-- | resources/clj-kondo/config.edn | 7 | ||||
| -rw-r--r-- | resources/clj-kondo/hooks/dompa.clj | 27 |
2 files changed, 32 insertions, 2 deletions
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.")))))))) + |
