diff --git a/packages/eslint-plugin/src/rules/no-extra-parens.ts b/packages/eslint-plugin/src/rules/no-extra-parens.ts index 24659aedfe4b..71bfc4f10dc0 100644 --- a/packages/eslint-plugin/src/rules/no-extra-parens.ts +++ b/packages/eslint-plugin/src/rules/no-extra-parens.ts @@ -122,7 +122,19 @@ export default util.createRule({ } }, // AssignmentExpression - // AwaitExpression + AwaitExpression(node) { + if (util.isTypeAssertion(node.argument)) { + // reduces the precedence of the node so the rule thinks it needs to be wrapped + return rules.AwaitExpression({ + ...node, + argument: { + ...node.argument, + type: AST_NODE_TYPES.SequenceExpression as any, + }, + }); + } + return rules.AwaitExpression(node); + }, BinaryExpression: binaryExp, CallExpression: callExp, // ClassDeclaration @@ -148,7 +160,7 @@ export default util.createRule({ }); } if (util.isTypeAssertion(node.alternate)) { - // reduces the precedence of the node so the rule thinks it needs to be rapped + // reduces the precedence of the node so the rule thinks it needs to be wrapped return rules.ConditionalExpression({ ...node, alternate: { diff --git a/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts b/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts index 5f5dc37896fa..5a72b6015a21 100644 --- a/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts @@ -19,6 +19,8 @@ ruleTester.run('no-extra-parens', rule, { valid: [ ...batchedSingleLineTests({ code: ` +async function f(arg: any) { await (arg as Promise); } +async function f(arg: Promise) { await arg; } (0).toString(); (function(){}) ? a() : b(); (/^a$/).test(x); @@ -238,6 +240,9 @@ for (a of (b)); typeof (a); a((1)); new a((1)); +a<(A)>((1)); +async function f(arg: Promise) { await (arg); } +async function f(arg: any) { await ((arg as Promise)); } `, output: ` a = b * c; @@ -248,7 +253,9 @@ for (a of b); typeof a; a(1); new a(1); -a<(A)>((1)); +a<(A)>(1); +async function f(arg: Promise) { await arg; } +async function f(arg: any) { await (arg as Promise); } `, errors: [ { @@ -296,6 +303,16 @@ a<(A)>((1)); line: 10, column: 8, }, + { + messageId: 'unexpected', + line: 11, + column: 45, + }, + { + messageId: 'unexpected', + line: 12, + column: 37, + }, ], }), ...batchedSingleLineTests({ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy