diff --git a/lib/rules/semi-style.js b/lib/rules/semi-style.js index fa258754dcb..97fcc3ac820 100644 --- a/lib/rules/semi-style.js +++ b/lib/rules/semi-style.js @@ -79,7 +79,7 @@ module.exports = { : "the beginning of the next line" }, fix(fixer) { - if (commentsExistBetween(prevToken, nextToken)) { + if (prevToken && nextToken && commentsExistBetween(prevToken, nextToken)) { return null; } diff --git a/tests/lib/rules/semi-style.js b/tests/lib/rules/semi-style.js index a0281bff709..43968facffb 100644 --- a/tests/lib/rules/semi-style.js +++ b/tests/lib/rules/semi-style.js @@ -113,6 +113,12 @@ ruleTester.run("semi-style", rule, { options: ["last"], errors: ["Expected this semicolon to be at the end of the previous line."] }, + { + code: "foo()\n;", + output: "foo();\n", + options: ["last"], + errors: ["Expected this semicolon to be at the end of the previous line."] + }, { code: "foo;\nbar",