Skip to content

Commit

Permalink
Fix: max-statements-per-line rule to force minimum to be 1 (fixes #7051
Browse files Browse the repository at this point in the history
…) (#7092)
  • Loading branch information
sstern6 authored and vitorbal committed Sep 12, 2016
1 parent e462e47 commit c85fd84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
20 changes: 2 additions & 18 deletions lib/rules/max-statements-per-line.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
properties: {
max: {
type: "integer",
minimum: 0
minimum: 1
}
},
additionalProperties: false
Expand Down Expand Up @@ -185,23 +185,7 @@ module.exports = {
"ExportNamedDeclaration:exit": leaveStatement,
"ExportDefaultDeclaration:exit": leaveStatement,
"ExportAllDeclaration:exit": leaveStatement,
"Program:exit": reportFirstExtraStatementAndClear,

// For backward compatibility.
// Empty blocks should be warned if `{max: 0}` was given.
BlockStatement: function reportIfZero(node) {
if (maxStatementsPerLine === 0 && node.body.length === 0) {
context.report({
node,
message,
data: {
numberOfStatementsOnThisLine: 0,
maxStatementsPerLine,
statements: "statements",
}
});
}
}
"Program:exit": reportFirstExtraStatementAndClear
};
}
};
5 changes: 2 additions & 3 deletions tests/lib/rules/max-statements-per-line.js
Expand Up @@ -20,7 +20,6 @@ const ruleTester = new RuleTester();

ruleTester.run("max-statements-per-line", rule, {
valid: [
{ code: "", options: [{ max: 0 }] },
{ code: "{ }", options: [{ max: 1 }] },
{ code: "var bar = 1;" },
{ code: "var bar = 1;", options: [{ max: 1 }] },
Expand Down Expand Up @@ -117,8 +116,8 @@ ruleTester.run("max-statements-per-line", rule, {
}
],
invalid: [
{ code: "{ }", options: [{ max: 0 }], errors: [{ message: "This line has 0 statements. Maximum allowed is 0." }] },
{ code: "var bar = 1;", options: [{ max: 0 }], errors: [{ message: "This line has 1 statement. Maximum allowed is 0." }] },
{ code: "var foo; var bar;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
{ code: "var bar = 1; var foo = 3;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
{ code: "var bar = 1; var baz = 2;", errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
{ code: "var bar = 1; var baz = 2;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
{ code: "if (condition) var bar = 1; if (condition) var baz = 2;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
Expand Down

0 comments on commit c85fd84

Please sign in to comment.