Add `commentPattern` option to `no-fallthrough` rule
See original GitHub issueWhat version of ESLint are you using?
2.5.3
What rule do you want to change?
no-fallthrough
What code should be flagged as incorrect with this change?
/*eslint no-fallback: ["error", { "commentPattern": "break[\\s\\w]*omitted" }]*/
switch(foo) {
case 0: a();
/* fallthrough */
default: c();
}
What happens when the rule is applied to this code now?
Errors:
Expected a 'break' statement before 'case'.
Expected a 'break' statement before 'default'.
It seems useful to be able to customize the comment pattern for intentional fallthrough (default pattern for now is /falls?\s?through/i
), especially when one tends to write comments in a language other than english. Consider:
/*eslint no-fallback: ["error", { "commentPattern": "break" }]*/
switch (foo) {
case 0: a();
// break пропущен умышленно!
case 1: b();
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (9 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 >How do I safely fix ESLint`no-fallthrough` error for intentional ...
1 · Tried adding /* eslint no-fallthrough: ["error", { "allowEmptyCase": true }] */ (above switch) and // falls through (next to switch statement) ......
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 >Warning Options (Using the GNU Compiler Collection (GCC))
The option argument n specifies what kind of comments are accepted: -Wimplicit-fallthrough=0 disables the warning altogether. -Wimplicit-fallthrough=1 matches .
Read more >Getting Started With ESLint - Medium
A “best practices” rule example is no-fallthrough , which disallows case statements that do not properly use break to prevent a “fall through”...
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
I guess it makes sense for
no-empty
andno-empty-function
to accept any comment vs.no-fallthrough
. I would be OK with adding a new option to bothno-fallthrough
andno-default-case
to accept RegEx.Okay, we will use this issue to track
no-fallthrough
. Please open a separate issue forno-default-case
.