From 9fcfabfb3b99c79b7adc42a7a72f3df90eab2fa6 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 4 Jan 2018 13:53:57 -0500 Subject: [PATCH] Fix: no-extra-parens false positive (fixes: #9755) (#9795) --- docs/rules/no-extra-parens.md | 14 ++++++++++++++ lib/rules/no-extra-parens.js | 2 +- tests/lib/rules/no-extra-parens.js | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-extra-parens.md b/docs/rules/no-extra-parens.md index 392ac06a7ba..61fb50dc3e0 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 d8e0df64a7b..1025aa5a97c 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 7753c7d6682..cab241a0a3e 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -145,7 +145,9 @@ ruleTester.run("no-extra-parens", rule, { "do; while(a);", "for(;;);", "for(a in b);", + "for(a in b, c);", "for(a of b);", + "for (a of (b, c));", "var a = (b, c);", "[]", "[a, b]", @@ -1035,6 +1037,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) ] });