lue-bird / elm-review-equals-caseable / EqualsCaseable

Rule, reporting == when equivalent case of exists

forbid : ForbiddenLocation -> Review.Rule.Rule

Reports when == is used but there's there is an equivalent case of available.

config =
    [ EqualsCaseable.forbid EqualsCaseable.InIf
    ]

Where the given ForbiddenLocation can be either

reported

a =
    if list == [] then
        "empty"

    else
        "filled"

not reported

a =
    case list of
        [] ->
            "empty"

        _ :: _ ->
            "filled"


type ForbiddenLocation
    = InIf
    | Everywhere

Configuration option for EqualsCaseable.forbid. Can be either

"forbid only when used in the test of an if" → InIf

reported

a =
    if list == [] then
        "empty"

    else
        "filled"

not reported

a =
    case list of
        [] ->
            "empty"

        _ :: _ ->
            "filled"

"forbid always" → Everywhere

reported

a =
    if list == [] then
        "empty"

    else
        "filled"

b =
    users |> List.filter (\u -> u.role == Moderator)

not reported

a =
    users
        |> List.filter
            (\u ->
                case u.role of
                    Moderator ->
                        True

                    _ ->
                        False
            )

What should I choose?

If (\a -> a.something == Variant) etc is a very common pattern in your code base, you'll have an easier time converting all the ifs first.

To get the discussed benefits like "Now the compiler will tell me all the places I need to make a new decision", you do need to refactor all these equality checks.

Your goal should be EqualsCaseable.forbid Everywhere