Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ignore empty statements in no-unreachable (fixes #9081) #11058

Merged
merged 2 commits into from Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rules/no-unreachable.js
Expand Up @@ -151,8 +151,11 @@ module.exports = {
/*
* Report the current range since this statement is reachable or is
* not consecutive to the current range.
* Empty statements are not considered unreachable as they do not
* contains executable code. See
* https://github.com/eslint/eslint/issues/9081
*/
if (!range.isEmpty) {
if (!range.isEmpty && range.startNode.type !== "EmptyStatement") {
nzakas marked this conversation as resolved.
Show resolved Hide resolved
context.report({
message: "Unreachable code.",
loc: range.location,
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-unreachable.js
Expand Up @@ -32,6 +32,13 @@ ruleTester.run("no-unreachable", rule, {
"while (true) { if (true) break; var x = 1; }",
"while (true) continue;",
"switch (foo) { case 1: break; var x; }",
"switch (foo) { case 1: break; var x; default: throw true; };",
{
code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); };}",
parserOptions: {
ecmaVersion: 6
}
},
"var x = 1; y = 2; throw 'uh oh'; var y;",
"function foo() { var x = 1; if (x) { return; } x = 2; }",
"function foo() { var x = 1; if (x) { } else { return; } x = 2; }",
Expand Down