no-unreachable: shouldn't be triggered by a semicolon after switch
See original GitHub issueWhat 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:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 byno-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 enhanceno-unreachable
to have a different error message for EmptyStatements, to make it less confusing. But I don’t think we shouldn’t warn.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: