Skip to content

Commit 0f97be7

Browse files
authored
Merge pull request #32 from hlship/hls/20250127-lint-fix
Defeat clj-kondo's static type analysis
2 parents b36f9d8 + 31ef2fa commit 0f97be7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The `abort` function assumes an exit status of 1 if the first message passed is
66
It also now prints the tool and command name in bold green (to be conistent with
77
the rest of the library).
88

9+
The clj-kondo hook for the `defcommand` now produces slightly different code, that defeats
10+
the clj-kondo static type analysis, preventing spurious warnings about vectors passed
11+
to particular clojure.core functions.
12+
913
Dependencies were not properly declared for Clojure applications that use cli-tools
1014
(libraries that are bundled with Babashka were omitted).
1115

resources/clj-kondo.exports/io.github.hlship/cli-tools/cli_tools/hooks.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@
3434
(next more-terms)
3535
(update blocks :opts conj term (first more-terms)))))))
3636

37+
(defn xform-opts
38+
"This is a lot of work to actually defeat clj-kondo's normal static analysis.
39+
40+
See https://github.com/hlship/cli-tools/issues/28 for more info."
41+
[opts]
42+
(when (seq opts)
43+
(let [pairs (partition 2 opts)
44+
collector (api/token-node (gensym "options"))
45+
map-terms (mapcat (fn [[sym v]]
46+
[(api/keyword-node (-> sym str keyword)) v])
47+
pairs)]
48+
[collector
49+
(api/map-node (vec map-terms))
50+
51+
(api/map-node [(api/keyword-node :keys)
52+
(api/vector-node (map first pairs))])
53+
collector])))
3754

3855
(defn- parse-interface
3956
[interface]
@@ -45,7 +62,7 @@
4562
vector (api/vector-node
4663
(concat
4764
lets
48-
opts
65+
(xform-opts opts)
4966
afters))]
5067
vector))
5168

0 commit comments

Comments
 (0)