From 616a841032bec310d9f31f1c987888273df27008 Mon Sep 17 00:00:00 2001 From: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com> Date: Tue, 28 Jul 2020 00:22:18 +1000 Subject: [PATCH] fix(eslint-plugin): [no-extra-parens] stop reporting on calling generic functions with one argument and type parameters containing parentheses (#2319) --- .../src/rules/no-extra-parens.ts | 19 +++++++++++++++ .../tests/rules/no-extra-parens.test.ts | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/eslint-plugin/src/rules/no-extra-parens.ts b/packages/eslint-plugin/src/rules/no-extra-parens.ts index e3ab2395279..42fd53d3310 100644 --- a/packages/eslint-plugin/src/rules/no-extra-parens.ts +++ b/packages/eslint-plugin/src/rules/no-extra-parens.ts @@ -78,6 +78,25 @@ export default util.createRule({ }); } + if ( + node.arguments.length === 1 && + node.typeParameters?.params.some( + param => + param.type === AST_NODE_TYPES.TSParenthesizedType || + param.type === AST_NODE_TYPES.TSImportType, + ) + ) { + return rule({ + ...node, + arguments: [ + { + ...node.arguments[0], + type: AST_NODE_TYPES.SequenceExpression as any, + }, + ], + }); + } + return rule(node); } function unaryUpdateExpression( 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 45cdf1f99c1..d0868e8293d 100644 --- a/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extra-parens.test.ts @@ -26,6 +26,9 @@ for (a of (b, c)); for (a of b); for (a in b, c); for (a in b); +a(1); +new a(1); +a<(A)>(1); `, }), ...batchedSingleLineTests({ @@ -233,6 +236,8 @@ for (a in (b, c)); for (a in (b)); for (a of (b)); typeof (a); +a((1)); +new a((1)); `, output: ` a = b * c; @@ -241,6 +246,9 @@ for (a in b, c); for (a in b); for (a of b); typeof a; +a(1); +new a(1); +a<(A)>((1)); `, errors: [ { @@ -273,6 +281,21 @@ typeof a; line: 7, column: 8, }, + { + messageId: 'unexpected', + line: 8, + column: 15, + }, + { + messageId: 'unexpected', + line: 9, + column: 19, + }, + { + messageId: 'unexpected', + line: 10, + column: 8, + }, ], }), ...batchedSingleLineTests({