diff --git a/lib/rules/no-multiple-empty-lines.js b/lib/rules/no-multiple-empty-lines.js index f945cfeffe2..41e6be3a289 100644 --- a/lib/rules/no-multiple-empty-lines.js +++ b/lib/rules/no-multiple-empty-lines.js @@ -110,7 +110,7 @@ module.exports = { if (lineNumber - lastLineNumber - 1 > maxAllowed) { context.report({ node, - loc: { start: { line: lastLineNumber + 1, column: 0 }, end: { line: lineNumber, column: 0 } }, + loc: { start: { line: lastLineNumber + maxAllowed + 1, column: 0 }, end: { line: lineNumber, column: 0 } }, message, data: { max: maxAllowed, pluralizedLines: maxAllowed === 1 ? "line" : "lines" }, fix(fixer) { diff --git a/tests/lib/rules/no-multiple-empty-lines.js b/tests/lib/rules/no-multiple-empty-lines.js index 5c51dd81107..7b14f75ae35 100644 --- a/tests/lib/rules/no-multiple-empty-lines.js +++ b/tests/lib/rules/no-multiple-empty-lines.js @@ -316,6 +316,32 @@ ruleTester.run("no-multiple-empty-lines", rule, { output: "foo\n", options: [{ max: 1, maxEOF: 0 }], errors: [getExpectedErrorEOF(0)] + }, + { + + // https://github.com/eslint/eslint/pull/12594 + code: "var a;\n\n\n\n\nvar b;", + output: "var a;\n\nvar b;", + options: [{ max: 1 }], + errors: [{ + message: "More than 1 blank line not allowed.", + type: "Program", + line: 3, + column: 1 + }] + }, + { + + // https://github.com/eslint/eslint/pull/12594 + code: "var a;\n\n\n\n\nvar b;", + output: "var a;\n\n\nvar b;", + options: [{ max: 2 }], + errors: [{ + message: "More than 2 blank lines not allowed.", + type: "Program", + line: 4, + column: 1 + }] } ] });