Skip to content

Commit 2127acd

Browse files
committed
Add clj-kondo for better Calva support
1 parent fa1e032 commit 2127acd

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(ns com.fulcrologic.fulcro.clj-kondo-hooks
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn defmutation
5+
[{:keys [node]}]
6+
(let [args (rest (:children node))
7+
mutation-name (first args)
8+
?docstring (when (string? (api/sexpr (second args)))
9+
(second args))
10+
args (if ?docstring
11+
(nnext args)
12+
(next args))
13+
params (first args)
14+
handlers (rest args)
15+
handler-syms (map (comp first :children) handlers)
16+
bogus-usage (api/vector-node (vec handler-syms))
17+
letfn-node (api/list-node
18+
(list
19+
(api/token-node 'letfn)
20+
(api/vector-node (vec handlers))
21+
bogus-usage))
22+
new-node (api/list-node
23+
(list
24+
(api/token-node 'defn)
25+
mutation-name
26+
params
27+
letfn-node))]
28+
(doseq [handler handlers]
29+
(let [hname (some-> handler :children first api/sexpr str)
30+
argv (some-> handler :children second)]
31+
(when-not (= 1 (count (api/sexpr argv)))
32+
(api/reg-finding! (merge
33+
(meta argv)
34+
{:message (format "defmutation handler '%s' should be a fn of 1 arg" hname)
35+
:type :clj-kondo.fulcro.defmutation/handler-arity})))))
36+
{:node new-node}))
37+
38+
(defn >defn
39+
[{:keys [node]}]
40+
(let [args (rest (:children node))
41+
fn-name (first args)
42+
?docstring (when (string? (api/sexpr (second args)))
43+
(second args))
44+
args (if ?docstring
45+
(nnext args)
46+
(next args))
47+
argv (first args)
48+
gspec (second args)
49+
body (nnext args)
50+
new-node (api/list-node
51+
(list*
52+
(api/token-node 'defn)
53+
fn-name
54+
argv
55+
gspec
56+
body))]
57+
(when (not= (count (api/sexpr argv))
58+
(count (take-while #(not= '=> %) (api/sexpr gspec))))
59+
(api/reg-finding! (merge (meta gspec)
60+
{:message "Guardrail spec does not match function signature"
61+
:type :clj-kondo.fulcro.>defn/signature-mismatch})))
62+
{:node new-node}))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{:hooks {:analyze-call {com.fulcrologic.fulcro.mutations/defmutation com.fulcrologic.fulcro.clj-kondo-hooks/defmutation
2+
com.fulcrologic.guardrails.core/>defn com.fulcrologic.fulcro.clj-kondo-hooks/>defn}}
3+
:linters {:clj-kondo.fulcro.defmutation/handler-arity {:level :error}
4+
:clj-kondo.fulcro.>defn/signature-mismatch {:level :error}}
5+
:lint-as {com.fulcrologic.fulcro.components/defsc clojure.core/defn
6+
com.fulcrologic.fulcro.routing.dynamic-routing/defrouter clojure.core/defn
7+
com.fulcrologic.fulcro.ui-state-machines/defstatemachine clojure.core/def
8+
com.fulcrologic.guardrails.core/>def clojure.core/def
9+
com.fulcrologic.guardrails.core/>defn clojure.core/defn
10+
com.fulcrologic.rad.attributes/defattr clojure.core/def
11+
com.fulcrologic.rad.report/defsc-report clojure.core/defn
12+
com.fulcrologic.rad.form/defsc-form clojure.core/defn
13+
com.fulcrologic.rad.authorization/defauthenticator clojure.core/def}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{:lint-as {com.wsscode.async.async-clj/deftest-async clojure.test/deftest
2+
com.wsscode.async.async-clj/go-try-stream clojure.core/let
3+
com.wsscode.async.async-clj/let-chan clojure.core/let
4+
com.wsscode.async.async-clj/let-chan* clojure.core/let
5+
com.wsscode.async.async-cljs/deftest-async clojure.test/deftest
6+
com.wsscode.async.async-cljs/go-try-stream clojure.core/let
7+
com.wsscode.async.async-cljs/let-chan clojure.core/let
8+
com.wsscode.async.async-cljs/let-chan* clojure.core/let}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{:lint-as {com.wsscode.pathom.connect/defmutation clojure.core/defn
2+
com.wsscode.pathom.connect/defresolver clojure.core/defn}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{:lint-as
2+
{rewrite-clj.zip/subedit-> clojure.core/->
3+
rewrite-clj.zip/subedit->> clojure.core/->>
4+
rewrite-clj.zip/edit-> clojure.core/->
5+
rewrite-clj.zip/edit->> clojure.core/->>}}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ resources/public/js
1515
resources/public/workspaces/js
1616
.lsp/sqlite.db
1717
lsp
18-
.calva/output-window/output.calva-repl
18+
.calva/output-window/output.calva-repl
19+
.clj-kondo/.cache

0 commit comments

Comments
 (0)