diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 7afe7625dfc..37f0d650bf9 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -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) diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index c0d0387ec74..6e979b3e382 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -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 }] }, @@ -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 }] }),