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 doesn't seem to work

See original GitHub issue

Maybe I am missing something, but the following code snippet lints successfully when I enter it into http://eslint.org/demo/. I expected it to fail with no-fallthrough.

switch ("foo") {
case "foo":
case "bar":
    break;
default:
    throw new Error();
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, Apr 7, 2016

We originally had this as an exception because it’s a pretty common way to say you want fall through (even JSLint allows it):

switch (something) {
    case 1:
    case 2:
        yay();
}

My opinion is that this should still not warn. However, this definitely should warn:

switch (something) {
    case 1:
        // yay();
    case 2:
        yay();
}

So, if I’ve read this issue correct, it’s really the latter case that is problematic and I’d say it’s a bug that it’s not being flagged right now. @Grandrath is that correct?

1reaction
nzakascommented, Apr 11, 2016

Yup. If the two cases aren’t directly adjacent, then it should warn.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switch Fall Through Not Working as Expected - Stack Overflow
Your error is in believeing cases MSI and BI to be two different switch sections separated by an empty switch case body. There...
Read more >
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 >
Fallthrough in Switch Statements doesn't work for Patterns
Attempting to do fallthrough within switch statement with patterns does not work. See attached file for example of working pattern, non-stacked, ...
Read more >
switch - JavaScript - MDN Web Docs - Mozilla
Breaking and fall-through. You can use the break statement within a switch statement's body to break out early, often when all statements ...
Read more >
An end to implicit fall-throughs in the kernel - LWN.net
since the following is not valid C and a "raw" [[fallthrough]] is difficult ... doesn't work one though - the preprocessor will remove...
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