This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-17
Channels
- # adventofcode (56)
- # announcements (1)
- # aws (6)
- # beginners (127)
- # bristol-clojurians (1)
- # calva (29)
- # cider (7)
- # clj-kondo (37)
- # cljdoc (20)
- # cljsrn (7)
- # clojure (159)
- # clojure-europe (67)
- # clojure-italy (23)
- # clojure-nl (4)
- # clojure-provo (3)
- # clojure-uk (18)
- # clojurescript (19)
- # code-reviews (59)
- # community-development (105)
- # conjure (6)
- # core-async (16)
- # core-logic (1)
- # cursive (21)
- # datomic (19)
- # defnpodcast (1)
- # emacs (8)
- # events (2)
- # fulcro (71)
- # graalvm (23)
- # jobs-discuss (1)
- # kaocha (5)
- # luminus (5)
- # meander (16)
- # nrepl (32)
- # off-topic (6)
- # pathom (159)
- # pedestal (3)
- # reagent (14)
- # reitit (8)
- # reveal (12)
- # rewrite-clj (9)
- # shadow-cljs (169)
- # spacemacs (16)
- # specter (2)
- # sql (19)
- # tools-deps (36)
- # vim (6)
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.
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
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 😛
Isn’t that common though? When you are taking the children of a node and want to do stuff?
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…
In reality, (+ 1 b)
is never evaluated because b is nil, but clj-kondo flags: expected number, got nil
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
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...)