New rule proposal: default-case-last #12665
Labels
accepted
There is consensus among the team that this change meets the criteria for inclusion
archived due to age
This issue has been archived; please open a new issue for any further discussion
feature
This change adds a new feature to ESLint
rule
Relates to ESLint's core rules
Please describe what the rule should do:
Enforce
default
clauses inswitch
statements to be last.What category of rule is this? (place an "X" next to just one item)
[X] Suggests an alternate way of doing something (suggestion)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
This rule enforces a common convention.
Even if a non-last
default
might make sense for a specific situation, it's better to refactor the code to a more understandable version.A non-last
default
is, I believe, unexpected for readers. A reader might not know if it is a valid code at all, and what's the actual behavior (does the evaluation stop when it findsdefault
in the middle, does it execute thedefault
block and then continue searching, etc.).This rule applies only to
switch
statements that already havedefault
clauses. It doesn't enforce the existence ofdefault
clauses (there is thedefault-case
rule for that purpose).Are you willing to submit a pull request to implement this rule?
Yes.
The text was updated successfully, but these errors were encountered: