From 482786393c9397bf3edc39b034400eca1ccde27a Mon Sep 17 00:00:00 2001 From: cherryblossom <31467609+cherryblossom000@users.noreply.github.com> Date: Wed, 22 Jul 2020 19:42:05 +1000 Subject: [PATCH 1/2] fix(eslint-plugin): [no-extra-parens]: stop reporting on calling generic functions with one argument and type parameters containing parentheses (fixes #2314) --- .../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..fed8c746558 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({ From 4cf0906909dba5d9a9ce2e54da48a7f013d56d75 Mon Sep 17 00:00:00 2001 From: cherryblossom <31467609+cherryblossom000@users.noreply.github.com> Date: Wed, 22 Jul 2020 19:55:09 +1000 Subject: [PATCH 2/2] chore(eslint-plugin): add semicolons to tests --- .../tests/rules/no-extra-parens.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 fed8c746558..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,9 +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) +a(1); +new a(1); +a<(A)>(1); `, }), ...batchedSingleLineTests({ @@ -236,8 +236,8 @@ for (a in (b, c)); for (a in (b)); for (a of (b)); typeof (a); -a((1)) -new a((1)) +a((1)); +new a((1)); `, output: ` a = b * c; @@ -246,9 +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)) +a(1); +new a(1); +a<(A)>((1)); `, errors: [ {