Skip to content

Commit

Permalink
Fix: no-multiple-empty-lines: Adjust reported loc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Turbo87 committed Nov 25, 2019
1 parent af95154 commit 1491368
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-multiple-empty-lines.js
Expand Up @@ -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) {
Expand Down
26 changes: 26 additions & 0 deletions tests/lib/rules/no-multiple-empty-lines.js
Expand Up @@ -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\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
}]
}
]
});

0 comments on commit 1491368

Please sign in to comment.