Skip to content

Commit

Permalink
Fix: Ignore empty statements in no-unreachable (fixes #9081)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Nov 6, 2018
1 parent 7ad86de commit d926842
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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") {
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

0 comments on commit d926842

Please sign in to comment.