I'm reviewing and improving a PR for a linter that is called :conditional-build-up
(let [m {} m (if whatever (assoc m :foo :bar) m)] ..)
->
(cond-> {}
whatever (assoc :foo :bar))
I don't like the name of the linter. Suggestion: cond->candidate: it conveys that this pattern can be rewritten as cond->
Better suggestions welcome in π§΅decided to go with the existing name since none of the alternatives were compelling
IMO Iβd look for something without the condβ prefix as this would be used with a range of names. :conditional-thread-first and :conditional-thread-last came to mind
:cond-> means cond thread first?
Oh sorry, I confused it with :lint-as
maybe :let-if-to-cond> . I fear that a good name is very hard to find for this one
Does it only work on unnecessary 'let's or are there other cases as well?
Maybe something in the direction of prefer-condβ ?
Maybe redundant-let-to-condβ
prefer-cond-> would get my vote.
prefer-condβ is perfectly understandable for me.
However I don't see other prefer-* names in the linters. Looking at the linters to try to stay idiomatic it seems they are mostly named after detecting the pattern vs the fix. In that regard I think redundant-conditional-binding might be a good one.
Given that @borkdude has said redundant means "remove", I don't think that fits...?
It does remove the binding, doesn't it?
redundant-* means: you can remove it without affecting the program, e.g. (do x) -> x
(I am a bit surprised none of the existing linters have prefer...)
:conditional-rebind might also work. The original condβ-candidate seems pretty good too honestly π.
Maybe that's just because we don't have an existing prefer-* like thing? I have merged if-x-x-y which could be renamed to :prefer-or
have a meta config :prefer-prefer to rename all the linters
?
just a joke, I guess it didn't land π
:prefer-splint π€£
I guess I can just go ask AI for a good name then. Bye bye ;)
no but seriously, I don't think we have a linter yet that says: you should prefer this function/macro over the other
except for :not-empty? perhaps
and :not-nil? -> some?
but the above pattern is hard to capture in one name
Naming is hard.
perhaps prefer-cond-> should be it then. better than :conditional-build-up?
Are the linters mostly named for the thing it finds or the thing it thinks you should do? I suspect the former, based on the names I've seen discussed...
...in which case this should be named for what it finds conditional-build-up or conditional-rebinding or...?
:repeated-conditional-assoc
?(if x (assoc m :foo :bar) m)
==>
(cond-> m x (assoc :foo :bar))
I guess you don't even need to "repeat", but I think this linter now only fired when you do that twice:successive-conditional-assoc
is probably better