Skip to content

Commit 1fb490d

Browse files
committed
Add kondo support for internal deferred macros
Adds support for `success-error-unrealized` and `both`.
1 parent e6767c0 commit 1fb490d

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

.clj-kondo/config.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
:hooks {:analyze-call
1010
{manifold.stream.core/def-source manifold.hooks/def-sink-or-source
1111
manifold.stream.core/def-sink manifold.hooks/def-sink-or-source
12-
manifold.stream.core/def-sink+source manifold.hooks/def-sink-or-source}}
12+
manifold.stream.core/def-sink+source manifold.hooks/def-sink-or-source
13+
manifold.deferred/both manifold.hooks/both
14+
manifold.deferred/success-error-unrealized manifold.hooks/success-error-unrealized}}
1315

1416

1517
:config-in-call {manifold.stream.core/def-sink+source

.clj-kondo/manifold/hooks.clj

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,73 @@
2828
(api/token-node (symbol (str "->" (:string-value name))))
2929
bindings
3030
))))}))
31+
32+
(defn- seq-node? [node]
33+
(or (api/vector-node? node)
34+
(api/list-node? node)))
35+
36+
(defn- nth-child [node n] (nth (:children node) n))
37+
38+
(defn both [call]
39+
(let [body (-> call :node :children second :children)]
40+
41+
{:node
42+
(api/list-node
43+
(list
44+
(api/token-node 'do)
45+
46+
(api/list-node
47+
(->> body
48+
(mapcat
49+
#(if (and (seq-node? %) (= 'either (:value (nth-child % 0))))
50+
(:children (nth-child % 1))
51+
[%]))))
52+
53+
(api/list-node
54+
(->> body
55+
(mapcat
56+
#(if (and (seq-node? %) (= 'either (:value (nth-child % 0))))
57+
(:children (nth-child % 2))
58+
[%]))))))}))
59+
60+
61+
(def fallback-value
62+
"The fallback value used for declaration of local variables whose
63+
values are unknown at lint time."
64+
(api/list-node
65+
(list
66+
(api/token-node 'new)
67+
(api/token-node 'java.lang.Object))))
68+
69+
(defn success-error-unrealized [call]
70+
71+
(let [[deferred
72+
success-value success-clause
73+
error-value error-clause
74+
unrealized-clause] (-> call :node :children rest)]
75+
76+
(when-not (and deferred success-value success-clause error-value
77+
error-clause unrealized-clause)
78+
(throw (ex-info "Missing success-error-unrealized arguments" {})))
79+
80+
{:node
81+
(api/list-node
82+
(list
83+
(api/token-node 'do)
84+
85+
(api/list-node
86+
(list
87+
(api/token-node 'let)
88+
(api/vector-node (vector success-value fallback-value))
89+
success-clause
90+
))
91+
92+
(api/list-node
93+
(list
94+
(api/token-node 'let)
95+
(api/vector-node (vector error-value fallback-value))
96+
error-clause
97+
))
98+
99+
unrealized-clause
100+
))}))

0 commit comments

Comments
 (0)