Skip to content
Permalink
Browse files

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.
  • Loading branch information
Turbo87 authored and kaicataldo committed Dec 20, 2019
1 parent a258039 commit 272e4db6074283bc01cc6ec72c9e396bb3c110e6
Showing with 27 additions and 1 deletion.
  1. +1 −1 lib/rules/no-multiple-empty-lines.js
  2. +26 −0 tests/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) {
@@ -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
}]
}
]
});

0 comments on commit 272e4db

Please sign in to comment.
You can’t perform that action at this time.