Allow "never" in rule default-case
See original GitHub issueWhat rule do you want to change?
default-case
What change to do you want to make?
Generate more warnings
How do you think the change should be implemented?
A new option
Example code
/*eslint default-case: ["error", "never"]*/
switch (a) {
case 1:
/* code */
break;
default:
/* code */
break;
}
What does the rule currently do for this code?
Right now there is only an option to enforce that default cases must be used in switch statements, but no option to enforce that default should not be used at all. In my experience default cases bring more trouble because it indicates that some cases have not been handled. Also, it breaks type checking where the type system can detect if the switch case is exhaustive or not. For example by using switch-exhaustiveness-check
What will the rule do after it’s changed?
The rule will be able to be configured to not only enforce usage of default cases, but also to enforce not to use default cases.
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Rule suggestion: use of never #2616 - GitHub
I think the rule I want is "disallow any use of a never -typed value ... case 'a': return 1; case 'b': return...
Read more >Rule 55. Default; Default Judgment - Law.Cornell.Edu
A default judgment that does not dispose of all of the claims among all parties is not a final judgment unless the court...
Read more >Should switch statements always contain a default clause?
Nonexhaustive switch statements: Those should always have a default value. As the name suggests those are statements which do not cover all possible...
Read more >default-case - ESLint - Pluggable JavaScript Linter
This rule aims to require default case in switch statements. You may optionally include a // no default after the last case if...
Read more >Setting Aside A Civil Default Judgment
If the court has entered a default judgment against you, the plaintiff can collect it like any other judgment. That means she can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the input. As stated in the README, we actually aren’t making any further updates to rules that enforce stylistic preferences. If you have a strong preference for such a change, you can always copy the existing rule into a custom rule and make it behave the way you want.
Rules that accept special comments have a different purpose than rules that require/disallow some feature based on configuration. The purpose of rules that accept special comments is to enforce indicating the intention to use or not use a feature in places where using or not using that feature looks like a possible error, not to entirely require/disallow the feature.
default-case
treats missingdefault
cases as possible errors and requires a special comment to indicate intention.Similarly,
no-fallthrough
treats fallthroughs between cases as possible errors, and requires a special comment to indicate that the fallthrough was intentional.