Skip to content
Permalink
Browse files

Fix: Incorrect error at EOF for no-multiple-empty-lines (fixes #4917)

  • Loading branch information...
alberto committed Jan 13, 2016
1 parent 30da59b commit 86e6e570bf8c42e9b2f7862ab394843b4b178d73
Showing with 33 additions and 25 deletions.
  1. +1 −1 lib/rules/no-multiple-empty-lines.js
  2. +32 −24 tests/lib/rules/no-multiple-empty-lines.js
@@ -92,7 +92,7 @@ module.exports = function(context) {
}
} else {
// inside the last blank lines
if (blankCounter >= maxEOF) {
if (blankCounter > maxEOF) {
context.report(node, location,
"Too many blank lines at the end of file. Max of " + maxEOF + " allowed.");
}
@@ -56,52 +56,60 @@ ruleTester.run("no-multiple-empty-lines", rule, {

valid: [
{
code: "// valid 1\nvar a = 5;\nvar b = 3;",
code: "// valid 1\nvar a = 5;\nvar b = 3;\n\n",
options: [ { max: 1 } ]
},
{
code: "// valid 1\n\nvar a = 5;\n\nvar b = 3;",
code: "// valid 2\n\nvar a = 5;\n\nvar b = 3;",
options: [ { max: 1 } ]
},
{
code: "// valid 1\nvar a = 5;\n\nvar b = 3;",
code: "// valid 3\nvar a = 5;\n\nvar b = 3;\n\n\n",
options: [ { max: 2 } ]
},
{
code: "// valid 2\nvar a = 5,\n b = 3;",
code: "// valid 4\nvar a = 5,\n b = 3;",
options: [ { max: 2 } ]
},
{
code: "// valid 3\nvar a = 5;\n\n\n\n\nvar b = 3;",
code: "// valid 5\nvar a = 5;\n\n\n\n\nvar b = 3;\n\n\n\n\n",
options: [ { max: 4 } ]
},
{
code: "// valid 4\nvar a = 5;\n/* comment */\nvar b = 5;",
code: "// valid 6\nvar a = 5;\n/* comment */\nvar b = 5;",
options: [ { max: 0 } ]
},
{
code: "// valid 5\nvar a = 5;\n",
code: "// valid 7\nvar a = 5;\n",
options: [ { max: 0 } ]
},
{
code: "// valid 8\nvar a = 5;\n",
options: [ { max: 0, maxEOF: 0 } ]
},
{
code: "// valid 9\nvar a = 1;\n\n",
options: [{ "max": 2, "maxEOF": 1 }]
},

// template strings
{
code: "x = `\n\n\n\nhi\n\n\n\n`",
code: "// valid 10\nx = `\n\n\n\nhi\n\n\n\n`",
options: [ { max: 2 } ],
parserOptions: { ecmaVersion: 6 }
},
{
code: "`\n\n`",
code: "// valid 11\n`\n\n`",
options: [ { max: 0 } ],
parserOptions: { ecmaVersion: 6 }
},

{
code: "// valid 5\nvar a = 5;\n\n\n\n",
code: "// valid 12\nvar a = 5;\n\n\n\n\n",
options: [ { max: 0, maxEOF: 4 } ]
},
{
code: "// valid 5\nvar a = 5;\n\n\n\n",
code: "// valid 13\nvar a = 5;\n\n\n\n",
options: [ { max: 3 } ]
}
],
@@ -113,67 +121,67 @@ ruleTester.run("no-multiple-empty-lines", rule, {
options: [ { max: 1 } ]
},
{
code: "// invalid 1\n\n\n\n\nvar a = 5;",
code: "// invalid 2\n\n\n\n\nvar a = 5;",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 2\nvar a = 5;\n\n\n\n",
code: "// invalid 3\nvar a = 5;\n\n\n\n",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 2\nvar a = 5;\n \n \n \n",
code: "// invalid 4\nvar a = 5;\n \n \n \n",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 3\nvar a=5;\n\n\n\nvar b = 3;",
code: "// invalid 5\nvar a=5;\n\n\n\nvar b = 3;",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 3\nvar a=5;\n\n\n\nvar b = 3;\n",
code: "// invalid 6\nvar a=5;\n\n\n\nvar b = 3;\n",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 4\nvar a = 5;\n\n\n\nb = 3;\nvar c = 5;\n\n\n\nvar d = 3;",
code: "// invalid 7\nvar a = 5;\n\n\n\nb = 3;\nvar c = 5;\n\n\n\nvar d = 3;",
errors: 2,
options: [ { max: 2 } ]
},
{
code: "// invalid 5\nvar a = 5;\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 3;",
code: "// invalid 8\nvar a = 5;\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 3;",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 6\nvar a=5;\n\n\n\n\n",
code: "// invalid 9\nvar a=5;\n\n\n\n\n",
errors: [ getExpectedError(2) ],
options: [ { max: 2 } ]
},
{
code: "// invalid 7\nvar a = 5;\n\nvar b = 3;",
code: "// invalid 10\nvar a = 5;\n\nvar b = 3;",
errors: [ getExpectedError(0) ],
options: [ { max: 0 } ]
},
{
code: "// valid 5\nvar a = 5;\n\n",
code: "// invalid 11\nvar a = 5;\n\n\n",
errors: [ getExpectedErrorEOF(1) ],
options: [ { max: 5, maxEOF: 1 } ]
},
{
code: "// valid 5\nvar a = 5;\n\n\n\n\n",
code: "// invalid 12\nvar a = 5;\n\n\n\n\n\n",
errors: [ getExpectedErrorEOF(4) ],
options: [ { max: 0, maxEOF: 4 } ]
},
{
code: "// valid 5\n\n\n\n\n\n\n\n\nvar a = 5;\n\n",
code: "// invalid 13\n\n\n\n\n\n\n\n\nvar a = 5;\n\n\n",
errors: [ getExpectedErrorEOF(1) ],
options: [ { max: 10, maxEOF: 1 } ]
},
{
code: "// valid 5\nvar a = 5;\n",
code: "// invalid 14\nvar a = 5;\n\n",
errors: [ getExpectedErrorEOF(0) ],
options: [ { max: 2, maxEOF: 0 } ]
}

0 comments on commit 86e6e57

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