Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [no-extra-parens] stop reporting on calling gener…
…ic functions with one argument and type parameters containing parentheses (#2319)
  • Loading branch information
cherryblossom000 committed Jul 27, 2020
1 parent fd90e31 commit 616a841
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/eslint-plugin/src/rules/no-extra-parens.ts
Expand Up @@ -78,6 +78,25 @@ export default util.createRule<Options, MessageIds>({
});
}

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(
Expand Down
23 changes: 23 additions & 0 deletions packages/eslint-plugin/tests/rules/no-extra-parens.test.ts
Expand Up @@ -26,6 +26,9 @@ for (a of (b, c));
for (a of b);
for (a in b, c);
for (a in b);
a<import('')>(1);
new a<import('')>(1);
a<(A)>(1);
`,
}),
...batchedSingleLineTests({
Expand Down Expand Up @@ -233,6 +236,8 @@ for (a in (b, c));
for (a in (b));
for (a of (b));
typeof (a);
a<import('')>((1));
new a<import('')>((1));
`,
output: `
a = b * c;
Expand All @@ -241,6 +246,9 @@ for (a in b, c);
for (a in b);
for (a of b);
typeof a;
a<import('')>(1);
new a<import('')>(1);
a<(A)>((1));
`,
errors: [
{
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 616a841

Please sign in to comment.