diff --git a/docs/rules/no-extra-parens.md b/docs/rules/no-extra-parens.md index 392ac06a7baa..138128161f32 100644 --- a/docs/rules/no-extra-parens.md +++ b/docs/rules/no-extra-parens.md @@ -36,6 +36,12 @@ a = (b * c); (a * b) + c; +for (a in (b, c)); + +for (a in (b)); + +for (a of (b); + typeof (a); (function(){} ? a() : b()); @@ -55,6 +61,14 @@ Examples of **correct** code for this rule with the default `"all"` option: (function(){}) ? a() : b(); (/^a$/).test(x); + +for (a of (b, c)); + +for (a of b); + +for (a in b, c); + +for (a in b); ``` ### conditionalAssign diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index d8e0df64a7b2..1025aa5a97c4 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -582,7 +582,7 @@ module.exports = { tokensToIgnore.add(firstLeftToken); } } - if (hasExcessParens(node.right)) { + if (!(node.type === "ForOfStatement" && node.right.type === "SequenceExpression") && hasExcessParens(node.right)) { report(node.right); } if (hasExcessParens(node.left)) { diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 7753c7d66828..4bd417d7e199 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -146,6 +146,7 @@ ruleTester.run("no-extra-parens", rule, { "for(;;);", "for(a in b);", "for(a of b);", + "for (a of (b, c));", "var a = (b, c);", "[]", "[a, b]", @@ -1035,6 +1036,7 @@ ruleTester.run("no-extra-parens", rule, { "for (let.foo.bar in baz);", "Identifier", 1 - ) + ), + invalid("for (a in (b, c));", "for (a in b, c);", "SequenceExpression", null) ] });