clj-kondo

https://github.com/clj-kondo/clj-kondo
2021-04-06T14:04:14.206900Z

Hey folks. Just checking if I’m not missing anything – is there any linter rule for avoiding thread macro abuse? That is, catching things like (-> foo :bar) (should be (:bar foo) or (-> foo :bar :baz) (prefer (get-in foo [:bar :baz]) )

cjsauer 2021-04-07T17:27:28.218900Z

https://github.com/roterski/fulcro-rad-crux/blob/6baba4fcdf710ed801938067a1b5fe95ee39f8d6/src/main/roterski/fulcro/rad/database_adapters/crux/wrap_crux_save.clj#L103-L116 might change my mind on this linter. Sometimes it really is more readable to use a threading maco with only 2 args, like in the case of a reduce with a large reducing function.

tvaughan 2021-04-06T14:06:28.207Z

Not clj-kondo, but fyi nonetheless https://github.com/jonase/kibit

cjsauer 2021-04-06T14:08:11.207400Z

I have a love-hate relationship with kibit. It has a couple helpful linters in it, but it’s really slow, and doesn’t support a lot of cljs syntax (which is what I work in most often). I imagine adding a linter to kondo that detects this issue would be really simple. Looking to see where this would go in the source code…

borkdude 2021-04-06T15:13:50.208900Z

(-> foo :bar :baz) vs (prefer (get-in foo [:bar :baz]) )
can't say that I would endorse this, since the -> variant is often faster

borkdude 2021-04-06T15:13:56.209100Z

and it's pretty idiomatic as well

cjsauer 2021-04-06T15:32:33.209300Z

Yea, I actually end up disagreeing with kibit on that exact case. Still, I think the trivial case of (-> foo :bar) is safe to prefer (:bar foo). So the linter would check if you’re using -> with only 2 args, and nothing fancier.

2021-04-06T15:33:50.209500Z

Yeap, I think we can all agree on that one.