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

Suggestion: Remove n * 1 simplification #198

Open jfmengels opened 11 months ago

jfmengels commented 11 months ago

Multiplication by 1 is one of the first and common complaints about this rule. Here's an example of where people would like to keep it

module NBSeconds exposing (oneDay, oneWeek)
nbOfSecondsInADay = 60 * 60 * 24

oneWeek = 7 * nbOfSecondsInADay

oneDay = 1 * nbOfSecondsInADay

Given the code above, Simplify will tell the user to change oneDay to oneDay = nbOfSecondsInADay, which users feels is surprising and/or less readable.

I'm therefore wondering whether we should remove this simplification. I think we could still remove code like 1 * 1 as I'm having a lot more trouble imagining a situation where that is needed.

I think keeping 1 */* 1 prevents us from doing some simplifications (like n == 1 * n -> n == n -> True), although I believe we could special-case 1 * to be ignored in these situations.