Skip to content

Commit 616a841

Browse files
fix(eslint-plugin): [no-extra-parens] stop reporting on calling generic functions with one argument and type parameters containing parentheses (#2319)
1 parent fd90e31 commit 616a841

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/eslint-plugin/src/rules/no-extra-parens.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ export default util.createRule<Options, MessageIds>({
7878
});
7979
}
8080

81+
if (
82+
node.arguments.length === 1 &&
83+
node.typeParameters?.params.some(
84+
param =>
85+
param.type === AST_NODE_TYPES.TSParenthesizedType ||
86+
param.type === AST_NODE_TYPES.TSImportType,
87+
)
88+
) {
89+
return rule({
90+
...node,
91+
arguments: [
92+
{
93+
...node.arguments[0],
94+
type: AST_NODE_TYPES.SequenceExpression as any,
95+
},
96+
],
97+
});
98+
}
99+
81100
return rule(node);
82101
}
83102
function unaryUpdateExpression(

packages/eslint-plugin/tests/rules/no-extra-parens.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ for (a of (b, c));
2626
for (a of b);
2727
for (a in b, c);
2828
for (a in b);
29+
a<import('')>(1);
30+
new a<import('')>(1);
31+
a<(A)>(1);
2932
`,
3033
}),
3134
...batchedSingleLineTests({
@@ -233,6 +236,8 @@ for (a in (b, c));
233236
for (a in (b));
234237
for (a of (b));
235238
typeof (a);
239+
a<import('')>((1));
240+
new a<import('')>((1));
236241
`,
237242
output: `
238243
a = b * c;
@@ -241,6 +246,9 @@ for (a in b, c);
241246
for (a in b);
242247
for (a of b);
243248
typeof a;
249+
a<import('')>(1);
250+
new a<import('')>(1);
251+
a<(A)>((1));
244252
`,
245253
errors: [
246254
{
@@ -273,6 +281,21 @@ typeof a;
273281
line: 7,
274282
column: 8,
275283
},
284+
{
285+
messageId: 'unexpected',
286+
line: 8,
287+
column: 15,
288+
},
289+
{
290+
messageId: 'unexpected',
291+
line: 9,
292+
column: 19,
293+
},
294+
{
295+
messageId: 'unexpected',
296+
line: 10,
297+
column: 8,
298+
},
276299
],
277300
}),
278301
...batchedSingleLineTests({

0 commit comments

Comments
 (0)