eslint: no-fallthrough doesn't seem to work

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();
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (17 by maintainers)

Commits related to this issue

Most upvoted comments

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?

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