Skip to content

Commit

Permalink
Fix: Ignore empty statements in no-unreachable (fixes #9081) (#11058)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored and mysticatea committed Nov 8, 2018
1 parent 7ad86de commit dcc6233
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/rules/no-unreachable.js
Expand Up @@ -182,7 +182,6 @@ module.exports = {
ContinueStatement: reportIfUnreachable,
DebuggerStatement: reportIfUnreachable,
DoWhileStatement: reportIfUnreachable,
EmptyStatement: reportIfUnreachable,
ExpressionStatement: reportIfUnreachable,
ForInStatement: reportIfUnreachable,
ForOfStatement: reportIfUnreachable,
Expand Down
21 changes: 21 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 Expand Up @@ -63,6 +70,20 @@ ruleTester.run("no-unreachable", rule, {
{ code: "function foo() { var x = 1; while (x) { if (x) break; else continue; x = 2; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] },
{ code: "function foo() { var x = 1; for (;;) { if (x) continue; } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] },
{ code: "function foo() { var x = 1; while (true) { } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] },
{
code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); }; g() }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Unreachable code.",
type: "ExpressionStatement",
line: 1,
column: 86,
endLine: 1,
endColumn: 89
}
]
},

// Merge the warnings of continuous unreachable nodes.
{
Expand Down

0 comments on commit dcc6233

Please sign in to comment.