Fork me on GitHub
#clj-kondo
<
2021-04-06
>
apt14:04:14

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]) )

tvaughan14:04:28

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

cjsauer14:04:11

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…

borkdude15:04:50

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

borkdude15:04:56

and it's pretty idiomatic as well

cjsauer15:04:33

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.

apt15:04:50

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

cjsauer17:04:28

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.