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-unreachable: shouldn't be triggered by a semicolon after switch

See original GitHub issue

What version of ESLint are you using? v2.11.0

What parser (default, Babel-ESLint, etc.) are you using? Occurs with either espree or babel-eslint.

Please show your full configuration: Anything with no-unreachable enabled…

What did you do? Please include the actual source code causing the issue.

This triggers 5:4 error Unreachable code no-unreachable

function foo(bar) {
  switch (bar) {
    default:
      return bar;
  };
}

This doesn’t…

function foo(bar) {
  switch (bar) {
    default:
      return bar;
  }
}

(the only difference being in the semicolon after the switch)

What did you expect to happen?

I would have expected no-unreachable not to trigger on semicolon… (there’s other rules for that 😃).

What actually happened? Please include the actual, raw output from ESLint.

5:4 error Unreachable code no-unreachable

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, May 31, 2016

@mysticatea Isn’t it true that someone could turn off no-extra-semi though? Then they would get no warning at all, if EmptyStatements are allowed by no-unreachable.

Personally, I see nothing wrong with having two lint errors show up for two different issues. The unreachable-ness of the semicolon has nothing to do with the fact that it’s an unnecessary/empty statement; the emptiness of the statement has nothing to do with the fact that it is unreachable.

Personally I would say this is working as designed and we don’t need to enhance it. I think we could enhance no-unreachable to have a different error message for EmptyStatements, to make it less confusing. But I don’t think we shouldn’t warn.

1reaction
platinumazurecommented, Jun 6, 2016

I’m not sure I understand why you think you need the semicolon after switch in the first place. It’s completely unnecessary and it’s not allowed by the language (that is, a SwitchStatement in the grammar does not allow an optional semicolon like simple statements do, and any semicolon you do place is unambiguously an empty and unnecessary statement). On Jun 6, 2016 11:10 AM, “Martin Hradil” notifications@github.com wrote:

Exactly, I do understand that from the parser’s standpoint it really is an unreachable statement. But it means there’s currently no way to allow semicolon after switch and get no warnings while still wanting to be warned about nonempty unreachable statements…

Maybe just adding an ignoreEmpty option to no-unreachable would work? (and yes, I’m willing to implement that 😃)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/6295#issuecomment-224006999, or mute the thread https://github.com/notifications/unsubscribe/AARWer2533NzLNdyVrkTA9oxnHo0T2gnks5qJEaIgaJpZM4IqQ6x .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning for "unreachable expression after semicolon-less ...
It says "SyntaxError: unreachable expression after semicolon-less return statement", but the expression isn't actually unreachable, because the return is ...
Read more >
semicolon in fall through of switch case statement
In C a semicolon marks the end of a code block/statement, even if there is nothing in it. I would be significant following...
Read more >
7.5 — Switch fallthrough and scoping - Learn C++
When execution flows from a statement underneath a label into statements underneath a subsequent label, this is called fallthrough. Warning.
Read more >
whether semicolon exists for switch statement - Codecademy
No line is reachable after return , in any construct. Depending upon the conditions in the switch, and the function dictates, we can...
Read more >
Documentation - TypeScript 1.8
Statements guaranteed to not be executed at run time are now correctly flagged as unreachable code errors. For instance, statements following unconditional ...
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