Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-switch-case-fall-through: Expect break before default #1033

Closed
unional opened this issue Mar 12, 2016 · 2 comments
Closed

no-switch-case-fall-through: Expect break before default #1033

unional opened this issue Mar 12, 2016 · 2 comments

Comments

@unional
Copy link
Contributor

unional commented Mar 12, 2016

Hi, I was expecting no-switch-case-fall-through to catch issues like this:

switch (prop) {
  case 1:
    // do stuff...
    // forget to break....
  case 2:
    // do stuff...
    break;
  default:
    // do stuff...
    break;

But it also catches these:

switch (prop) {
  case 1:
  case 2:
    // do stuff...
    break;
  case 3:
  default:
    // do stuff...
    break;
}

I think that (especially the default case) is a pretty common and valid pattern. What do you think?

@jkillian
Copy link
Contributor

You can add a special /* falls through */ comment, which will tell the rule that you want to allow a fall through to happen. I think

  case 3:
  default:

should be allowed though, seems like a bug in the rule potentially.

@HolgerJeromin
Copy link
Contributor

I think this is a bug as the comment

// no break statements and no statements means the fallthrough is expected.

mention it as a valid case.
And perhaps the test is wrong, too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants