Skip to content

Commit

Permalink
Fix: no-extra-parens false positive (fixes: #9755) (#9795)
Browse files Browse the repository at this point in the history
  • Loading branch information
erindepew authored and ilyavolodin committed Jan 4, 2018
1 parent 61e5fa0 commit 9fcfabf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/rules/no-extra-parens.md
Expand Up @@ -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());
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-extra-parens.js
Expand Up @@ -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)) {
Expand Down
5 changes: 4 additions & 1 deletion tests/lib/rules/no-extra-parens.js
Expand Up @@ -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]",
Expand Down Expand Up @@ -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)
]
});

0 comments on commit 9fcfabf

Please sign in to comment.