Skip to content

Commit

Permalink
Merge pull request #4343 from briandela/issue4342
Browse files Browse the repository at this point in the history
Fix: Update the message to include number of lines (fixes #4342)
  • Loading branch information
ilyavolodin committed Nov 6, 2015
2 parents 9bffbfd + 8b7c3a6 commit 7af5f56
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/rules/no-multiple-empty-lines.js
Expand Up @@ -88,13 +88,13 @@ module.exports = function(context) {
// within the file, not at the end
if (blankCounter >= max) {
context.report(node, location,
"Multiple blank lines not allowed.");
"More than " + max + " blank lines not allowed.");
}
} else {
// inside the last blank lines
if (blankCounter >= maxEOF) {
context.report(node, location,
"Too many blank lines at the end of file.");
"Too many blank lines at the end of file. Max of " + maxEOF + " allowed.");
}
}

Expand Down
66 changes: 46 additions & 20 deletions tests/lib/rules/no-multiple-empty-lines.js
Expand Up @@ -17,20 +17,46 @@ var rule = require("../../../lib/rules/no-multiple-empty-lines"),
//------------------------------------------------------------------------------

var ruleTester = new RuleTester(),
expectedError = {
messsage: "Multiple blank lines not allowed.",
type: "Program"
},
expectedErrorEOF = {
messsage: "Too many blank lines at the end of file.",
type: "Program"
},
ruleArgs = [
{
max: 2
}
];

/**
* Creates the expected error message object for the specified number of lines
* @param {lines} lines - The number of lines expected.
* @returns {object} the expected error message object
* @private
*/
function getExpectedError(lines) {
if (typeof lines !== "number") {
lines = 2;
}

return {
message: "More than " + lines + " blank lines not allowed.",
type: "Program"
};
}

/**
* Creates the expected error message object for the specified number of lines
* @param {lines} lines - The number of lines expected.
* @returns {object} the expected error message object
* @private
*/
function getExpectedErrorEOF(lines) {
if (typeof lines !== "number") {
lines = 0;
}

return {
message: "Too many blank lines at the end of file. Max of " + lines + " allowed.",
type: "Program"
};
}

ruleTester.run("no-multiple-empty-lines", rule, {

valid: [
Expand Down Expand Up @@ -80,27 +106,27 @@ ruleTester.run("no-multiple-empty-lines", rule, {
invalid: [
{
code: "// invalid 1\n\n\n\n\nvar a = 5;",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 2\nvar a = 5;\n\n\n\n",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 2\nvar a = 5;\n \n \n \n",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 3\nvar a=5;\n\n\n\nvar b = 3;",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 3\nvar a=5;\n\n\n\nvar b = 3;\n",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
Expand All @@ -110,37 +136,37 @@ ruleTester.run("no-multiple-empty-lines", rule, {
},
{
code: "// invalid 5\nvar a = 5;\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 3;",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 6\nvar a=5;\n\n\n\n\n",
errors: [ expectedError ],
errors: [ getExpectedError() ],
options: ruleArgs
},
{
code: "// invalid 7\nvar a = 5;\n\nvar b = 3;",
errors: [ expectedError ],
errors: [ getExpectedError(0) ],
options: [ { max: 0 } ]
},
{
code: "// valid 5\nvar a = 5;\n\n",
errors: [ expectedErrorEOF ],
errors: [ getExpectedErrorEOF(1) ],
options: [ { max: 5, maxEOF: 1 } ]
},
{
code: "// valid 5\nvar a = 5;\n\n\n\n\n",
errors: [ expectedErrorEOF ],
errors: [ getExpectedErrorEOF(4) ],
options: [ { max: 0, maxEOF: 4 } ]
},
{
code: "// valid 5\n\n\n\n\n\n\n\n\nvar a = 5;\n\n",
errors: [ expectedErrorEOF ],
errors: [ getExpectedErrorEOF(1) ],
options: [ { max: 10, maxEOF: 1 } ]
},
{
code: "// valid 5\nvar a = 5;\n",
errors: [ expectedErrorEOF ],
errors: [ getExpectedErrorEOF(0) ],
options: [ { max: 2, maxEOF: 0 } ]
}
]
Expand Down

0 comments on commit 7af5f56

Please sign in to comment.