Is clj-kondo able to pick up files with -
in the name rather than _
?
So if I had test/practicalli/lintme-test.clj
instead of test/practicalli/lintme_test.clj
I would get a warning.
clj-kondo will lint any file you throw at it
but it does not tell me I should have used an underscore. I assume this is out of scope
Maybe you're asking about this? https://github.com/borkdude/clj-kondo/issues/842
Still waiting for @pez's PR ;)
Feel free to "upvote" the issue with a thumbs up
(this is Github's silly way to prioritize issues)
Haha, never heard the “Yes, fits this project” signal. 😃
Not that you didn’t send it. It was just lost somewhere in transit. Haha.
So I’ve put better-cond in my codebase… and clj-kondo can’t read it (obviously). I started implementing a hook for it but it’s tricky. @borkdude I remember you used it as an example but I’m quite lost since the discussions were using a different syntax.
@orestis I have a test hook for better-cond: https://github.com/borkdude/clj-kondo/blob/master/corpus/.clj-kondo/hooks/better_cond.clj
which I used to test-drive the hook functionality. But I'm not sure how complete it is
Feel free to add it to https://github.com/clj-kondo/config
It’s not complete, but it’s a good starting point. I’ll bother you with some things if I don’t manage to finish it 🙂
Do you have a way to easily debug the various expressions? I’m trying to call api/sexpr
but it seems to only work on the top level and I’d like to avoid writing the recursive version 😛
@orestis Just call prn
or println
on the node
I get [<token: do> <list: (whena(dob))>]
(no spacing)
which I think means:
(do (when a (do b)))
but I’m not surethis is usually a sign that you garbled something
ah good to know 🙂
it seems you have a vector of nodes and not a node object itself
Isn’t that common though? When you are taking the children of a node and want to do stuff?
this happens to me too, just keep printing and iterating ;)
yes, but you should put the children back into some node:
(api/vector-node children)
and not [children]
in order for it to be a valid node
Ah right, I was trying to figure out if it should be a vector-node or a list-node or what?
I’m getting the hang of this:
(defn process-pairs [pairs]
(loop [[[lhs rhs :as pair] & pairs] pairs
new-body [(api/token-node 'do)]]
(if pair
(let [lhs-sexpr (api/sexpr lhs)]
(clojure.core/cond
;; single trailing element, flush the body
(= 1 (count pair))
(api/list-node (conj new-body lhs))
;; when node, recurse
(#{:when 'when} lhs-sexpr)
(api/list-node
(conj new-body (api/list-node
[(api/token-node 'when)
rhs
(process-pairs pairs)])))
;; let-like nodes
(#{:let :when-let :when-some
'let 'when-let 'when-some} lhs-sexpr)
(api/list-node (conj new-body
(api/list-node
[(api/token-node 'let)
rhs
(process-pairs pairs)])))
;; normal conditions, just add them to the body
:else
(recur pairs
(conj new-body lhs rhs))))
;; no trailing element, flush the body
(api/list-node new-body))))
(def cond
(fn [{:keys [node]}]
(let [expr (let [args (rest (:children node))
pairs (partition-all 2 args)]
(process-pairs pairs))]
;(println "COND" {:node (api/sexpr expr)})
{:node (with-meta expr
(meta node))})))
This deals with most cases — but not the “early bailing” ones (e.g. when-let) because the type-checking continues…
I bet better-cond would come in handy here ;)
(b/cond
:when-let [b nil]
(+ 1 b))
In reality, (+ 1 b)
is never evaluated because b is nil, but clj-kondo flags: expected number, got nil
ah, that gives a false positive?
who uses nil
in when-let though?
that's not a realistic use case
It’s not too bad in practice since you never use explicit nils but doing the full thing would probably mean just lifting the implementation 1-1
Gotta run 🙂 I’ll continnue this tomorrow.
:thumbsup:
Idle thought: do you imagine clj-kondo might grow to include a --autofix flag to make the obvious corrections (e.g. remove redundant lets, remove unused bindings, convert if to when...)