Skip to content

Commit 34ed55d

Browse files
authored
Merge pull request #224 from figurantpp/internal-kondo
Add clj-kondo support for internal macros
2 parents d709a7e + 1b95cd6 commit 34ed55d

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

.clj-kondo/config.edn

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{:lint-as {manifold.utils/definterface+ clojure.core/definterface
2+
manifold.utils/deftype+ clojure.core/deftype
3+
manifold.utils/defrecord+ clojure.core/defrecord
4+
manifold.utils/defprotocol+ clojure.core/defprotocol}
5+
6+
:hooks {:analyze-call
7+
{manifold.stream.core/def-source manifold.hooks/def-sink-or-source
8+
manifold.stream.core/def-sink manifold.hooks/def-sink-or-source
9+
manifold.stream.core/def-sink+source manifold.hooks/def-sink-or-source
10+
manifold.deferred/both manifold.hooks/both
11+
manifold.deferred/success-error-unrealized manifold.hooks/success-error-unrealized}}
12+
13+
14+
:config-in-call {manifold.stream.core/def-sink+source
15+
{:linters {:redefined-var {:level :off}}}
16+
17+
manifold.stream.core/def-sink
18+
{:linters {:redefined-var {:level :off}}}
19+
20+
manifold.stream.core/def-source
21+
{:linters {:redefined-var {:level :off}}}}
22+
23+
:config-paths ["../resources/clj-kondo.exports/manifold/manifold/"]}

.clj-kondo/manifold/hooks.clj

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(ns manifold.hooks
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn- cons-vector-node
5+
[node parent]
6+
(api/vector-node (cons node (:children parent))))
7+
8+
(defn def-sink-or-source [call]
9+
(let [[name bindings & body] (-> call :node :children rest)
10+
extended-bindings
11+
(cons-vector-node (api/token-node 'lock) bindings)]
12+
13+
{:node
14+
(api/list-node
15+
(list
16+
(api/token-node 'do)
17+
18+
(api/list-node
19+
(list*
20+
(api/token-node 'deftype)
21+
name
22+
extended-bindings
23+
body))
24+
25+
(api/list-node
26+
(list
27+
(api/token-node 'defn)
28+
(api/token-node (symbol (str "->" (:string-value name))))
29+
bindings))))}))
30+
31+
(defn- seq-node? [node]
32+
(or (api/vector-node? node)
33+
(api/list-node? node)))
34+
35+
(defn- nth-child [node n] (nth (:children node) n))
36+
37+
(defn both [call]
38+
(let [body (-> call :node :children second :children)
39+
expand-nth
40+
(fn [n item]
41+
(if (and (seq-node? item) (= 'either (:value (nth-child item 0))))
42+
(:children (nth-child item n))
43+
[item]))]
44+
45+
{:node
46+
(api/list-node
47+
(list
48+
(api/token-node 'do)
49+
50+
(api/list-node
51+
(->> body (mapcat (partial expand-nth 1))))
52+
53+
(api/list-node
54+
(->> body (mapcat (partial expand-nth 2))))))}))
55+
56+
57+
(def fallback-value
58+
"The fallback value used for declaration of local variables whose
59+
values are unknown at lint time."
60+
(api/list-node
61+
(list
62+
(api/token-node 'new)
63+
(api/token-node 'java.lang.Object))))
64+
65+
(defn success-error-unrealized [call]
66+
67+
(let [[deferred
68+
success-value success-clause
69+
error-value error-clause
70+
unrealized-clause] (-> call :node :children rest)]
71+
72+
(when-not (and deferred success-value success-clause error-value
73+
error-clause unrealized-clause)
74+
(throw (ex-info "Missing success-error-unrealized arguments" {})))
75+
76+
{:node
77+
(api/list-node
78+
(list
79+
(api/token-node 'do)
80+
81+
(api/list-node
82+
(list
83+
(api/token-node 'let)
84+
(api/vector-node (vector success-value fallback-value))
85+
success-clause))
86+
87+
(api/list-node
88+
(list
89+
(api/token-node 'let)
90+
(api/vector-node (vector error-value fallback-value))
91+
error-clause))
92+
93+
unrealized-clause))}))

0 commit comments

Comments
 (0)