Skip to content

Commit

Permalink
Fix: false positive with await and ** in no-extra-parens (fixes #12739)…
Browse files Browse the repository at this point in the history
… (#13923)
  • Loading branch information
mdjermanovic authored Dec 18, 2020
1 parent d93c935 commit 555c128
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ module.exports = {

if (!shouldSkipLeft && hasExcessParens(node.left)) {
if (
!(node.left.type === "UnaryExpression" && isExponentiation) &&
!(["AwaitExpression", "UnaryExpression"].includes(node.left.type) && isExponentiation) &&
!astUtils.isMixedLogicalAndCoalesceExpressions(node.left, node) &&
(leftPrecedence > prec || (leftPrecedence === prec && !isExponentiation)) ||
isParenthesisedTwice(node.left)
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ ruleTester.run("no-extra-parens", rule, {
"async function a() { await (a + await b) }",
"async function a() { (await a)() }",
"async function a() { new (await a) }",
"async function a() { await (a ** b) }",
"async function a() { (await a) ** b }",

{ code: "(foo instanceof bar) instanceof baz", options: ["all", { nestedBinaryExpressions: false }] },
{ code: "(foo in bar) in baz", options: ["all", { nestedBinaryExpressions: false }] },
{ code: "(foo + bar) + baz", options: ["all", { nestedBinaryExpressions: false }] },
Expand Down Expand Up @@ -1187,6 +1190,8 @@ ruleTester.run("no-extra-parens", rule, {
invalid("async function a() { await (+a); }", "async function a() { await +a; }", "UnaryExpression", null),
invalid("async function a() { +(await a); }", "async function a() { +await a; }", "AwaitExpression", null),
invalid("async function a() { await ((a,b)); }", "async function a() { await (a,b); }", "SequenceExpression", null),
invalid("async function a() { a ** (await b); }", "async function a() { a ** await b; }", "AwaitExpression", null),

invalid("(foo) instanceof bar", "foo instanceof bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),
invalid("(foo) in bar", "foo in bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),
invalid("(foo) + bar", "foo + bar", "Identifier", 1, { options: ["all", { nestedBinaryExpressions: false }] }),
Expand Down

0 comments on commit 555c128

Please sign in to comment.