Reports single-pattern case expressions, which may be written more concisely
or removed entirely.
config =
[ NoSinglePatternCase.rule
]
Fail
Single-pattern case expressions for destructuring are not allowed, as:
type Opaque
= Opaque Int
unpack : Opaque -> Opaque
unpack o =
case o of
Opaque i ->
i
may instead be written more concisely as:
unpack : Opaque -> Opaque
unpack (Opaque i) =
i
Similarly, single-pattern case expressions that ase not used for destructuring
are not allowed, as:
type AOrB
= A
| B
pointless : AOrB -> Bool
pointless aOrB =
case aOrB of
_ ->
True
may instead be written more concisely as:
pointless : AOrB -> Bool
pointless _ =
True
or
pointless : AOrB -> Bool
pointless =
always True
Success
Any case expression with more than one pattern match will not be reported.
Consider using jfmengels/elm-review-simplify
to detect unnecessary multi-pattern cases.
When (not) to enable this rule
This rule is useful if you prefer destructuring in e.g. function arguments or
let bindings, rather than in a single-pattern case.
This rule is not useful if you prefer the more verbose style.
Try it out
You can try this rule out by running the following command:
Reports single-pattern case expressions, which may be written more concisely or removed entirely.
Fail
Single-pattern case expressions for destructuring are not allowed, as:
may instead be written more concisely as:
Similarly, single-pattern case expressions that ase not used for destructuring are not allowed, as:
may instead be written more concisely as:
or
Success
Any case expression with more than one pattern match will not be reported. Consider using
jfmengels/elm-review-simplifyto detect unnecessary multi-pattern cases.When (not) to enable this rule
This rule is useful if you prefer destructuring in e.g. function arguments or
letbindings, rather than in a single-pattern case.This rule is not useful if you prefer the more verbose style.
Try it out
You can try this rule out by running the following command: