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])
)
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.
Not clj-kondo, but fyi nonetheless https://github.com/jonase/kibit
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…
(-> foo :bar :baz) vs (prefer (get-in foo [:bar :baz]) )
can't say that I would endorse this, since the ->
variant is often fasterand it's pretty idiomatic as well
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.
Yeap, I think we can all agree on that one.