Skip to content

Commit

Permalink
Fix: allow semi as braceless body of statements (fixes #6386)
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto committed Jun 13, 2016
1 parent 6b08cfc commit 46614fb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rules/no-extra-semi.js
Expand Up @@ -66,7 +66,16 @@ module.exports = {
*/
EmptyStatement: function(node) {
var parent = node.parent,
allowedParentTypes = ["ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"];
allowedParentTypes = [
"ForStatement",
"ForInStatement",
"ForOfStatement",
"WhileStatement",
"DoWhileStatement",
"IfStatement",
"LabeledStatement",
"WithStatement"
];

if (allowedParentTypes.indexOf(parent.type) === -1) {
report(node);
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/no-extra-semi.js
Expand Up @@ -27,6 +27,10 @@ ruleTester.run("no-extra-semi", rule, {
"do;while(0);",
"for(a in b);",
{ code: "for(a of b);", parserOptions: { ecmaVersion: 6 } },
"if(true);",
"if(true); else;",
"foo: ;",
"with(foo);",

// Class body.
{code: "class A { }", parserOptions: { ecmaVersion: 6 }},
Expand Down Expand Up @@ -76,6 +80,36 @@ ruleTester.run("no-extra-semi", rule, {
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "for(a of b);"
},
{
code: "if(true);;",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "if(true);"
},
{
code: "if(true){} else;;",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "if(true){} else;"
},
{
code: "if(true){;} else {;}",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }, { message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "if(true){} else {}"
},
{
code: "foo:;;",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "foo:;"
},
{
code: "with(foo);;",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "with(foo);"
},
{
code: "with(foo){;}",
errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }],
output: "with(foo){}"
},

// Class body.
{
Expand Down

0 comments on commit 46614fb

Please sign in to comment.