Skip to content

Commit 272e4db

Browse files
Turbo87Kai Cataldo
authored andcommitted
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.
1 parent a258039 commit 272e4db

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/rules/no-multiple-empty-lines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports = {
110110
if (lineNumber - lastLineNumber - 1 > maxAllowed) {
111111
context.report({
112112
node,
113-
loc: { start: { line: lastLineNumber + 1, column: 0 }, end: { line: lineNumber, column: 0 } },
113+
loc: { start: { line: lastLineNumber + maxAllowed + 1, column: 0 }, end: { line: lineNumber, column: 0 } },
114114
message,
115115
data: { max: maxAllowed, pluralizedLines: maxAllowed === 1 ? "line" : "lines" },
116116
fix(fixer) {

tests/lib/rules/no-multiple-empty-lines.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,32 @@ ruleTester.run("no-multiple-empty-lines", rule, {
316316
output: "foo\n",
317317
options: [{ max: 1, maxEOF: 0 }],
318318
errors: [getExpectedErrorEOF(0)]
319+
},
320+
{
321+
322+
// https://github.com/eslint/eslint/pull/12594
323+
code: "var a;\n\n\n\n\nvar b;",
324+
output: "var a;\n\nvar b;",
325+
options: [{ max: 1 }],
326+
errors: [{
327+
message: "More than 1 blank line not allowed.",
328+
type: "Program",
329+
line: 3,
330+
column: 1
331+
}]
332+
},
333+
{
334+
335+
// https://github.com/eslint/eslint/pull/12594
336+
code: "var a;\n\n\n\n\nvar b;",
337+
output: "var a;\n\n\nvar b;",
338+
options: [{ max: 2 }],
339+
errors: [{
340+
message: "More than 2 blank lines not allowed.",
341+
type: "Program",
342+
line: 4,
343+
column: 1
344+
}]
319345
}
320346
]
321347
});

0 commit comments

Comments
 (0)