jfmengels / elm-review-simplify

Provides elm-review rules to simplify your Elm code
https://package.elm-lang.org/packages/jfmengels/elm-review-simplify/latest/
BSD 3-Clause "New" or "Revised" License
20 stars 9 forks source link

Detect parenthesized composition #209

Closed lue-bird closed 11 months ago

lue-bird commented 11 months ago

This is more a note to self for the future: Currently, only inversesCompositionCheck, toggleCompositionChecks support reporting the first 2 in

(f >> earlier) >> later
earlier >> (later >> g)
(f >> earlier) >> (later >> g)
-- even with infinitely nested parens
(f >> (g >> earlier)) >> later
earlier >> ((later >> f) >> g)
(f >> (g >> earlier)) >> ((later >> h) >> i)

with any combination of >> and <<.

In practice, this means adding earlier.removeRange, later.removeRange to CompositionIntoChecks and re-checking that the fixes work using these.

Advantages

jfmengels commented 11 months ago

I think that for (f >> earlier) >> later, we could simply have a fix that reports the parentheses. That would be a simplification in itself too.

If we do that, I think it could still make sense to improve our support/understanding of later << (f >> earlier), although a case could be made that the order should be made that that should be simplified. Though I don't think this rule should/could tell which composition operator should be preferred.