diff --git a/lib/rules/eol-last.js b/lib/rules/eol-last.js index 24b0c9279c71..a1ebcaee28f9 100644 --- a/lib/rules/eol-last.js +++ b/lib/rules/eol-last.js @@ -86,10 +86,15 @@ module.exports = { }); } else if (mode === "never" && endsWithNewline) { + const secondLastLine = sourceCode.lines[sourceCode.lines.length - 1]; + // File is newline-terminated, but shouldn't be context.report({ node, - loc: location, + loc: { + start: { line: sourceCode.lines.length - 1, column: secondLastLine.length }, + end: { line: sourceCode.lines.length, column: 0 } + }, messageId: "unexpected", fix(fixer) { const finalEOLs = /(?:\r?\n)+$/u, diff --git a/tests/lib/rules/eol-last.js b/tests/lib/rules/eol-last.js index 0600c0daba84..91ba9f5abb0f 100644 --- a/tests/lib/rules/eol-last.js +++ b/tests/lib/rules/eol-last.js @@ -83,10 +83,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 2, + line: 1, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 2, + endColumn: 1 }] }, { @@ -96,10 +96,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 2, + line: 1, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 2, + endColumn: 1 }] }, { @@ -109,10 +109,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 3, + line: 2, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 3, + endColumn: 1 }] }, { @@ -122,10 +122,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 3, + line: 2, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 3, + endColumn: 1 }] }, { @@ -135,10 +135,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 3, + line: 2, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 3, + endColumn: 1 }] }, { @@ -148,10 +148,10 @@ ruleTester.run("eol-last", rule, { errors: [{ messageId: "unexpected", type: "Program", - line: 3, + line: 2, column: 1, - endLine: void 0, - endColumn: void 0 + endLine: 3, + endColumn: 1 }] },