Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns
exhaustively list all specific cases if possible
https://github.com/lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns
case-of elm elm-review exhaustive explicit variant
Last synced: 20 days ago
JSON representation
exhaustively list all specific cases if possible
- Host: GitHub
- URL: https://github.com/lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns
- Owner: lue-bird
- License: mit
- Created: 2024-10-03T18:19:05.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T09:40:32.000Z (2 months ago)
- Last Synced: 2024-12-09T18:02:07.567Z (24 days ago)
- Topics: case-of, elm, elm-review, exhaustive, explicit, variant
- Language: Elm
- Homepage: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns/latest/
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
The [`elm-review`](https://package.elm-lang.org/packages/jfmengels/elm-review/latest/) rule
[`NoCatchAllForSpecificRemainingPatterns.rule`](https://package.elm-lang.org/packages/lue-bird/elm-review-no-catch-all-for-specific-remaining-patterns/1.0.0/NoCatchAllForSpecificRemainingPatterns#rule) enforces that all specific cases are listed if possible.Below would be reported for example
```elm
type Resource
= Loaded String
| FailedToLoad String
| LoadingdisplayResource : Resource -> String
displayResource resource =
case resource of
Loaded text ->
Ui.text text
_ ->
Ui.spinner
```Try it:
```bash
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
```elm
module ReviewConfig exposing (config)import NoCatchAllForSpecificRemainingPatterns
import Review.Rule exposing (Rule)config : List Rule
config =
[ NoCatchAllForSpecificRemainingPatterns.rule
]
```## why?
- no accidentally missed cases:
```elm
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:
```elm
type Resource
= Loaded String
| FailedToLoad String
| Loading
-- added
| PartiallyLoaded StringdisplayResource : 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
```elm
case result of
Ok geoLocation ->
let
...
in
a
bunchOf
code_ ->
-- what is _ ?
0
```## not implemented (yet?)
- nested patterns like in tuples, variants or lists