diff --git a/lib/rules/max-statements-per-line.js b/lib/rules/max-statements-per-line.js index 1ee83fe0e7af..888ec37eda0f 100644 --- a/lib/rules/max-statements-per-line.js +++ b/lib/rules/max-statements-per-line.js @@ -22,7 +22,7 @@ module.exports = { properties: { max: { type: "integer", - minimum: 0 + minimum: 1 } }, additionalProperties: false @@ -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 }; } }; diff --git a/tests/lib/rules/max-statements-per-line.js b/tests/lib/rules/max-statements-per-line.js index 279b510fa033..c10ad7110341 100644 --- a/tests/lib/rules/max-statements-per-line.js +++ b/tests/lib/rules/max-statements-per-line.js @@ -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 }] }, @@ -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." }] },