question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-fallthrough does not allow comments between empty cases

See original GitHub issue

Multiple 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Nov 5, 2016

There’s also the commentPattern: option: http://eslint.org/docs/rules/no-fallthrough#commentpattern

If 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?

0reactions
not-an-aardvarkcommented, Dec 14, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found