Skip to content

Commit 1b95cd6

Browse files
committed
Add minor improvements to clj-kondo hooks
1 parent f36b321 commit 1b95cd6

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

.clj-kondo/manifold/hooks.clj

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
(list
2727
(api/token-node 'defn)
2828
(api/token-node (symbol (str "->" (:string-value name))))
29-
bindings
30-
))))}))
29+
bindings))))}))
3130

3231
(defn- seq-node? [node]
3332
(or (api/vector-node? node)
@@ -36,26 +35,23 @@
3635
(defn- nth-child [node n] (nth (:children node) n))
3736

3837
(defn both [call]
39-
(let [body (-> call :node :children second :children)]
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]))]
4044

4145
{:node
4246
(api/list-node
4347
(list
4448
(api/token-node 'do)
4549

4650
(api/list-node
47-
(->> body
48-
(mapcat
49-
#(if (and (seq-node? %) (= 'either (:value (nth-child % 0))))
50-
(:children (nth-child % 1))
51-
[%]))))
51+
(->> body (mapcat (partial expand-nth 1))))
5252

5353
(api/list-node
54-
(->> body
55-
(mapcat
56-
#(if (and (seq-node? %) (= 'either (:value (nth-child % 0))))
57-
(:children (nth-child % 2))
58-
[%]))))))}))
54+
(->> body (mapcat (partial expand-nth 2))))))}))
5955

6056

6157
(def fallback-value
@@ -86,15 +82,12 @@
8682
(list
8783
(api/token-node 'let)
8884
(api/vector-node (vector success-value fallback-value))
89-
success-clause
90-
))
85+
success-clause))
9186

9287
(api/list-node
9388
(list
9489
(api/token-node 'let)
9590
(api/vector-node (vector error-value fallback-value))
96-
error-clause
97-
))
91+
error-clause))
9892

99-
unrealized-clause
100-
))}))
93+
unrealized-clause))}))

0 commit comments

Comments
 (0)