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 when numbers cancel each other out in expression #123

Open jfmengels opened 1 year ago

jfmengels commented 1 year ago

This would be a follow-up to the idea in #41 and the PR done in #122.

The rule currently reports the following:

n - n
--> 0

-n + n
--> 0

but it doesn't catch something like this

something + n + else - n -- notice the 2 n cancel each other out
--> something + else

This would be nice to have, and I think that this will catch more problems than n - n.

Just like n - n, this simplification should not be enabled when we the rule is configured with expectNaN.