From 272e4db6074283bc01cc6ec72c9e396bb3c110e6 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 20 Dec 2019 21:24:02 +0100 Subject: [PATCH] Fix: no-multiple-empty-lines: Adjust reported `loc` (#12594) The `+ 1` was from a time where we warned about anything with more than one empty line, but since then the rule has become configurable. We should put the warning on the first line that breaks this rule, instead of on the second empty line. --- lib/rules/no-multiple-empty-lines.js | 2 +- tests/lib/rules/no-multiple-empty-lines.js | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 + }] } ] });