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

`if` inside `case` #229

Open miniBill opened 9 months ago

miniBill commented 9 months ago

What the rule should do: Infer the value from a simple case statement to use it to simplify if expressions

What problems does it solve: It helps during refactorings, especially when switching from if to case, and copying the old content inside branches

Example of things the rule would report:

case category of
    "Rock" ->
        if category == "Rock" then a else b
-->
case category of
    "Rock" ->
        a

Should this be part of the Simplify rule or should it be a new rule? Part of simplify. It ties into the inference code.

I am looking for:

jfmengels commented 9 months ago

We should also handle the opposite, when the case expression is inside the if:

if category == "Rock" then
  case category of
    "Rock" ->
        1
    _ ->
        2
else
   3
-->
if category == "Rock" then
  1
else
  3