Closed didibus closed 5 years ago
@didibus This is documented in the README:
https://github.com/borkdude/flycheck-clj-kondo#multiple-linters
Let me know if this works for you.
Ya, that doesn't work, in that, it does if flycheck chooses clj-kondo as the first linter. But flycheck happens to choose joker instead, don't know how it chooses it seems automatic.
You can set a buffer-local flycheck-checker
var to override it. If I set clj-kondo-clj for example, now I get the multiple checker chain. But I don't know how to default the correct clj-kondo checker automatically, so I don't have to manually override it for all buffers.
As a temporary solution, I've reversed the chain from your readme, so I add clj-kondo-... as the second linter after joker. But I don't like something that depends on arbitrary order, and since I don't know why flycheck picks joker first, I worry its brittle and might change in the future.
@didibus FWIW, in my init.el I first require flycheck-joker
, then flycheck-clj-kondo
and then I have the snippet from the README. I don't know enough about flycheck to say it's sensitive to ordering, but this works for me.
@didibus I tested if the order mattered and it did. When I require flycheck-joker
later than flycheck-clj-kondo
then the snippet from the README doesn't work. So maybe the last loaded checker "wins" and has to initiate the chain? The output of flycheck-verify-setup
didn't look different when I changed the order.
It may be due to the usage of:
(add-to-list 'flycheck-checkers 'clojure-joker)
vs.
(add-to-list 'flycheck-checkers 'clojure-joker 'append)
(see flycheck docs)
I see, this makes sense. The order of flycheck-checkers seems to dictate the order of the checkers. My issue now, is I use spacemacs, and it requires packages alphabetically. So clj-kondo is always added before, and because add-to-list adds to the front, joker being required last is added to the front, and made the first checker.
That means that, I don't have to worry about just having clj-kondo be the next checker over joker.
So my last question is, do you think it makes a difference if clj-kondo is next in the chain after joker, or should joker be next? Pros/Cons ?
I mean like this:
(dolist (checkers '((clojure-joker . clj-kondo-clj)
(clojurescript-joker . clj-kondo-cljs)
(clojure-joker . clj-kondo-cljc)))
(flycheck-add-next-checker (car checkers) (cons 'error (cdr checkers))))
@didibus To ensure the clj-kondo checkers are always before joker in the list of checkers, we could add this to the snippet in the README:
(dolist (checker '(clj-kondo-clj clj-kondo-cljs clj-kondo-cljc))
(setq flycheck-checkers (cons checker (delq checker flycheck-checkers))))
I don't think it matters which checker you call first, as long as you use the error
level in the chain.
@didibus If you're satisfied with the solution and I don't hear back from you, I'll add this snippet to the README:
;;;; setting up flycheck clj-kondo -> joker chain
;; ensure that clj-kondo checkers are at front of checker list
(dolist (checker '(clj-kondo-clj clj-kondo-cljs clj-kondo-cljc clj-kondo-edn))
(setq flycheck-checkers (cons checker (delq checker flycheck-checkers))))
;; clj-kondo calls joker after linting, even if there are errors
(dolist (checkers '((clj-kondo-clj . clojure-joker)
(clj-kondo-cljs . clojurescript-joker)
(clj-kondo-cljc . clojure-joker)
(clj-kondo-edn . edn-joker)))
(flycheck-add-next-checker (car checkers) (cons 'error (cdr checkers))))
Hey, I'm satisfied with the answer.
I'd say just mentioning that the order is based on the order of the checkers in flycheck-checkers could be helpful as well. In case someone else is having any kind of ordering issue in the future.
@didibus Co-incidentally, this was just added by @lispyclouds:
https://github.com/borkdude/clj-kondo/blob/master/doc/editor-integration.md#spacemacs
Fixed with 353e3481a20fbd577ad79db8bbc6113ce179c195
I'm actually experiencing a relevant issue. I've used this entire snippet:
;;;; setting up flycheck clj-kondo -> joker chain ;; ensure that clj-kondo checkers are at front of checker list (dolist (checker '(clj-kondo-clj clj-kondo-cljs clj-kondo-cljc clj-kondo-edn)) (setq flycheck-checkers (cons checker (delq checker flycheck-checkers)))) ;; clj-kondo calls joker after linting, even if there are errors (dolist (checkers '((clj-kondo-clj . clojure-joker) (clj-kondo-cljs . clojurescript-joker) (clj-kondo-cljc . clojure-joker) (clj-kondo-edn . edn-joker))) (flycheck-add-next-checker (car checkers) (cons 'error (cdr checkers))))
However, I'm getting an error saying Error while checking syntax automatically: (error "clj-kondo-clj is not a valid syntax checker")
. Weirdly, clj-kondo-edn
does make it to the front of flycheck-checkers
, but clj-kondo-clj
, clj-kondo-cljs
, clj-kondo-cljc
don't seem to.
My flycheck seems to default to using joker for linting for clj files. I'm not sure how to make it so it uses clj-kondo. I've added joker to the clj-kondo chain, but since it default to joker, it only runs that. I thought I could do it with add-hook, but I don't know how to distinguish between clj, cljc and cljs so I can set the appropriate clj-kondo linter.
Any idea?