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.

Add `commentPattern` option to `no-fallthrough` rule

See original GitHub issue

What 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:closed
  • Created 7 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ilyavolodincommented, Apr 1, 2016

I guess it makes sense for no-empty and no-empty-function to accept any comment vs. no-fallthrough. I would be OK with adding a new option to both no-fallthrough and no-default-case to accept RegEx.

0reactions
nzakascommented, Apr 6, 2016

Okay, we will use this issue to track no-fallthrough. Please open a separate issue for no-default-case.

Read more comments on GitHub >

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

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