Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-extra-parens] stop reporting on calling generic functions with one argument and type parameters containing parentheses #2319

Merged
merged 2 commits into from Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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