forbid using wildcard in pattern matching if it matches some, but not all, of a custom type's variants #131
GabrielBoehme13
started this conversation in
Rule ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What the rule should do:
The rule should report an error when a pattern match contains a wildcard (
_
or variable name) that handles some, but not all, of a custom type's variants. Either all of its variants must be listed explicitly, or they must all be matched by wildcard.(If exceptions are needed for some custom types, this rule would allow them to be specified in a List.)
This is a partial superset of the proposed
NoRedundantWildCard
rule by @jfmengels – this rule would handle partial pattern matching more broadly, but only for custom types. This rule would also very closely match a suggestion by @Janiczek from that same discussion.What problems does it solve:
It prevents us from accidentally opting out of the Elm compiler's assistance when a custom type is changed, and ensures that we have the exact list of custom types excluded from that assistance which we'd need to review manually.
Examples of things the rule would report:
Examples of things the rule would NOT report:
When (not) to enable this rule:
If most of your custom types specify long lists of variants which you regularly pattern match by listing only some of those variants, then you probably won't find this rule very useful.
If you want to guarantee that the Elm compiler can always identify needed code updates after a custom type change – while you keep a list of excluded custom types you've chosen to review manually instead – this would be the rule for you.
I am looking for:
NoInconsistentCustomTypeVariantMatching
is descriptive, but longBeta Was this translation helpful? Give feedback.
All reactions