The elm-review
rule
NoCatchAllForSpecificRemainingPatterns.rule
enforces that all specific cases are listed if possible.
Below would be reported for example
type Resource
= Loaded String
| FailedToLoad String
| Loading
displayResource : Resource -> String
displayResource resource =
case resource of
Loaded text ->
Ui.text text
_ ->
Ui.spinner
Try it:
elm-review --template lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns/example
If you like it, add it, add it to your configuration
module ReviewConfig exposing (config)
import NoCatchAllForSpecificRemainingPatterns
import Review.Rule exposing (Rule)
config : List Rule
config =
[ NoCatchAllForSpecificRemainingPatterns.rule
]
-
no accidentally missed cases:
patternIsZero expression = case expression of Elm.Syntax.Pattern.IntPattern int -> int == 0 _ -> -- accidentally missed HexPattern! False
-
a reminder if another variant is added in the future:
type Resource = Loaded String | FailedToLoad String | Loading -- added | PartiallyLoaded String displayResource : Resource -> String displayResource resource = case resource of Loaded text -> Ui.text text _ -> -- we actually should display partially loaded -- but the compiler doesn't remind us Ui.spinner
-
less jumping around to understand the code
case result of Ok geoLocation -> let ... in a bunchOf code _ -> -- what is _ ? 0
- nested patterns like in tuples, variants or lists