no-fallthrough does not allow comments between empty cases
See original GitHub issueMultiple cases with a single body are always allowed but placing comments between the cases is not allowed.
switch(foo) {
case 1:
case 2:
doSomething();
}
switch(foo) {
// We need to handle 1.
case 1:
// We also need to handle 2.
case 2:
doSomething();
}
The latter is not valid as the comment between case 1
and case 2
is not allowed. Would be great if it was possible to comment on individual cases without having to add the “fallthrough” comment after that.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (8 by maintainers)
Top Results From Across the Web
no-fallthrough - ESLint - Pluggable JavaScript Linter
Set the allowEmptyCase option to true to allow empty cases regardless of the layout. By default, this rule does not require a fallthrough...
Read more >Request: add option for no-fallthrough with newlines #15703
In all of the cases mentioned, the rule is behaving as expected. Only cases without empty lines or comments between them are considered ......
Read more >GCC 7, -Wimplicit-fallthrough warnings, and portable way to ...
Clang supports -Wimplicit-fallthrough warnings, but does not enable them as part of -Wall or -Wextra . Clang does not recognize comment ...
Read more >Usage of PSR-2 comment suggestion on no-break switch cases
There MUST be a comment such as // no break when fall-through is intentional in a non-empty case body. The PSR is especially...
Read more >no-switch-case-fall-through - Rule
Rule: no-switch-case-fall-through. Disallows falling through case statements. For example, the following is not allowed: switch(foo) { case 1: ...
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
There’s also the
commentPattern
: option: http://eslint.org/docs/rules/no-fallthrough#commentpatternIf you don’t want this behavior, wouldn’t it best to just turn the rule off? It sounds like what you’re trying to enforce is having ANY comment between cases make the rule consider the fall through case as valid, which is error prone and seems to me to defeat the purpose of enabling the rule.
Apologies if I’m misunderstanding something here and, if that’s the case, can you fill out the rule enhancement template as was requested when you first made the issue?
It looks like there hasn’t been any activity on this issue for awhile, and there are two 👎s from team members, so I’m going to go ahead and close it. Of course, you can always implement this behavior yourself as part of a custom rule.