Permalink
Browse files

Fix: ignore empty statements in max-statements-per-line (fixes #6153) (

  • Loading branch information...
alberto authored and ilyavolodin committed May 14, 2016
1 parent f9ca0d6 commit 1e0a65295e4d24217188133a35d89475778b1004
Showing with 19 additions and 13 deletions.
  1. +4 −0 lib/rules/max-statements-per-line.js
  2. +15 −13 tests/lib/rules/max-statements-per-line.js
@@ -67,6 +67,10 @@ module.exports = {
for (var i = 0, l = nodes.length; i < l; ++i) {
var currentStatement = nodes[i];
if (currentStatement.type === "EmptyStatement") {
continue;
}
if (currentStatement.loc.start.line === lastStatementLine) {
++numberOfStatementsOnThisLine;
} else {
@@ -24,6 +24,8 @@ ruleTester.run("max-statements-per-line", rule, {
{ code: "{ }", options: [{ max: 1 }] },
{ code: "var bar = 1;" },
{ code: "var bar = 1;", options: [{ max: 1 }] },
{ code: "var bar = 1;;"},
{ code: ";(function foo() {\n})()"},
{ code: "if (condition) var bar = 1;", options: [{ max: 1 }] },
{ code: "if (condition) { }", options: [{ max: 1 }] },
{ code: "if (condition) { } else { }", options: [{ max: 1 }] },
@@ -60,13 +62,13 @@ ruleTester.run("max-statements-per-line", rule, {
{ code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 3 }] },
{ code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 3 }] },
{ code: "switch (discriminant) { case 'test1': ; case 'test2': ; }", options: [{ max: 3 }] },
{ code: "let bar = bar => { ; }, baz = baz => { ; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } },
{ code: "function foo({[bar => { ; }]: baz = qux => { ; }}) { }", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } },
{ code: "bar => { ; }, baz => { ; }, qux => { ; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "[bar => { ; }, baz => { ; }, qux => { ; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "foo(bar => { ; }, baz => { ; }, qux => { ; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "({ bar: bar => { ; }, baz: baz => { ; }, qux: qux => { ; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "(bar => { ; }) ? (baz => { ; }) : (qux => { ; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }
{ code: "let bar = bar => { a; }, baz = baz => { b; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } },
{ code: "function foo({[bar => { a; }]: baz = qux => { b; }}) { }", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } },
{ code: "bar => { a; }, baz => { b; }, qux => { c; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "[bar => { a; }, baz => { b; }, qux => { c; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "foo(bar => { a; }, baz => { c; }, qux => { c; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "({ bar: bar => { a; }, baz: baz => { c; }, qux: qux => { ; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } },
{ code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }
],
invalid: [
{ code: "{ }", options: [{ max: 0 }], errors: [{ message: "This line has too many statements. Maximum allowed is 0." }] },
@@ -102,11 +104,11 @@ ruleTester.run("max-statements-per-line", rule, {
{ code: "if (condition) { var bar = 1; var baz = 2; var qux = 3; }", options: [{ max: 3 }], errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 3 }], errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "switch (discriminant) { case 'test': var bar = 1; break; default: var bar = 1; break; }", options: [{ max: 3 }], errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "let bar = bar => { ; }, baz = baz => { ; }, qux = qux => { ; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "(bar => { ; }) ? (baz => { ; }) : (qux => { ; });", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "bar => { ; }, baz => { ; }, qux => { ; }, quux => { ; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "[bar => { ; }, baz => { ; }, qux => { ; }, quux => { ; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "foo(bar => { ; }, baz => { ; }, qux => { ; }, quux => { ; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "({ bar: bar => { ; }, baz: baz => { ; }, qux: qux => { ; }, quux: quux => { ; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] }
{ code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 3." }] },
{ code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] },
{ code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has too many statements. Maximum allowed is 4." }] }
]
});

0 comments on commit 1e0a652

Please sign in to comment.