From 4a003552603ebb2157da2c3c22facdf2f312d303 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 7 Apr 2022 09:42:21 -0700 Subject: [PATCH] making clj-kondo commited. --- .clj-kondo/config.edn | 7 ++++++ .clj-kondo/hooks/defstate.clj | 46 +++++++++++++++++++++++++++++++++++ .gitignore | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .clj-kondo/config.edn create mode 100644 .clj-kondo/hooks/defstate.clj diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 00000000..092bba5b --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,7 @@ +{:linters {:clojure-lsp/unused-public-var {:exclude-when-defined-by #{mount.core/defstate}} + :clojure-lsp/unresolved-var {:exclude [(amazonica.aws.s3)]} + :unresolved-var {:exclude [amazonica.aws.s3]} + :private-call {:level :off} + :mount/defstate {:level :warning}} + + :hooks {:analyze-call {mount.core/defstate hooks.defstate/defstate}} } diff --git a/.clj-kondo/hooks/defstate.clj b/.clj-kondo/hooks/defstate.clj new file mode 100644 index 00000000..b047d38e --- /dev/null +++ b/.clj-kondo/hooks/defstate.clj @@ -0,0 +1,46 @@ +(ns hooks.defstate + (:require [clj-kondo.hooks-api :as api])) + +(defn defstate [{:keys [:node]}] + (let [args (rest (:children node)) + args (if (string? (api/sexpr (first args))) + (next args) + args) + [n & args] args + m (when-let [m (first (:meta n))] + (api/sexpr m)) + m (if (map? m) m {}) + ks (cond-> (take 1 args) + (> (count args) 2) (conj (nth args 2))) + invalid-key (first (remove (comp (partial contains? #{:start :stop}) api/sexpr) ks))] + (cond + invalid-key + (api/reg-finding! + {:message (str "lifecycle functions can only contain `:start` and `:stop`. illegal function found: " (api/sexpr invalid-key)) + :type :mount/defstate + :row (:row (meta invalid-key)) + :col (:col (meta invalid-key))}) + (not (contains? (set (map api/sexpr ks)) :start)) + (throw (ex-info "lifecycle functions must include `:start`" {})) + ((complement contains?) #{2 4} (count args)) + (throw (ex-info "lifecycle functions must consist of no more than 2 pair forms: `:start` and `:stop`" {})) + (and (contains? m :on-reload) (not (contains? #{:noop :stop} (:on-reload m)))) + (api/reg-finding! + {:message "metadata `:on-reload` key can only have value of `noop` or `stop`" + :type :mount/defstate + :row (:row (meta n)) + :col (:col (meta n))}) + :else + {:node + (api/list-node + (list + (api/token-node 'def) + n + (api/list-node + (list* + (api/token-node 'do) + (list* + + (api/token-node 'fn*) + (api/vector-node []) + args)))))}))) diff --git a/.gitignore b/.gitignore index 5c0bbc0f..28214862 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ private node_modules **/*.swp **/.DS_Store -.clj-kondo/** +.clj-kondo/.cache .calva/** .lsp/**