Skip to content

Commit

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

if (allowedParentTypes.indexOf(parent.type) === -1) {
report(node);
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/no-extra-semi.js
Expand Up @@ -27,6 +27,8 @@ 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;",

// Class body.
{code: "class A { }", parserOptions: { ecmaVersion: 6 }},
Expand Down Expand Up @@ -76,6 +78,21 @@ 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 {}"
},

// Class body.
{
Expand Down

0 comments on commit 5dcadb3

Please sign in to comment.