Request: add option for no-fallthrough with newlines
See original GitHub issueEnvironment
Node version: v16.14.0 npm version: v8.3.1 Local ESLint version: v8.11.0 (Currently used) Global ESLint version: v7.23.0 Operating System: darwin 21.1.0
What parser are you using?
Default (Espree)
What did you do?
var x = 3;
switch(x){
case 0:
case 1: break;
case 2:
case 3:
break;
}
What did you expect to happen?
No errors
What actually happened?
8:3 error Expected a 'break' statement before 'case' no-fallthrough
Participation
- I am willing to submit a pull request for this issue.
Additional comments
It might also make sense to support comments:
switch(x) {
// currently accepted
case 0:
case 1:
break;
// this issue
case 2:
case 3:
break;
// general proposal
/* a note about 4 */
case 4:
/* a note about 5 */
case 5:
break;
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:21 (11 by maintainers)
Top Results From Across the Web
no-fallthrough - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >sed: read whole file into pattern space without failing on single ...
Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more...
Read more >Warning Options (Using the GNU Compiler Collection (GCC))
When an unrecognized warning option is requested (e.g., -Wunknown-warning ), GCC emits a diagnostic stating that the option is not recognized.
Read more >Appending newlines characters (i.e. \r\n) to a form field sent in ...
So adding new line characters to the value of the text input element is basically superfluous. Alternative solutions might include: adding a ...
Read more >5 switch statement patterns · YourBasic Go
5 switch statement patterns. yourbasic.org/golang. Basic switch with default; No condition; Case list; Fallthrough; Exit with break; Execution order ...
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
Coming from other programming languages, ESLint’s current definition of fallthrough is inconsistent. @SheetJSDev talked about C/C++. Other languages:
PHP: PSR2 guidelines define fallthrough as requiring at least one statement. This is the same as C/C++
Java: Sun style defines a fallthrough as “doesn’t include a break statement”, so technically you always need a fallthrough comment between cases, no matter how much whitespace is in between.
Go: forced breaks at the end of each case clause, even if there is no whitespace. Special keyword
fallthrough
to fall through.Perl:
given
/when
statements do not fall through. Special keywordcontinue
to fall through.C#: compilation error if there is no break between case clauses, irrespective of the number of lines. Special statement
goto case ____
to fall throughRuby:
case
/when
statements do not fall throughRust:
match
does not have fallthrough support.Pascal:
case
statement has no fallthroughIn summary, “everything but eslint” defines fallthrough in one of two ways:
“intrinsic”: each case is separate.
case a: case b:
are seen as two distinct parts irrespective of the amount of whitespace and newlines between them.“statement”: at least one statement between case clauses with no final break.
ESLint’s behavior is surprising and feels inconsistent.
I genuinely tried to find an example outside of ESLint and came up short. Even in JS land:
JSHint takes the “statement” interpretation (you can verify on https://jshint.com/ )
JSLint takes the “statement” interpretation (you can verify on https://www.jslint.com/ )
ESLint “blazing a new trail” is not inherently bad, but there arguably should be a very compelling reason.