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] handle await with type assertion #5428

Merged
merged 3 commits into from Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions packages/eslint-plugin/src/rules/no-extra-parens.ts
Expand Up @@ -123,6 +123,19 @@ export default util.createRule<Options, MessageIds>({
},
// AssignmentExpression
// AwaitExpression
yeonjuan marked this conversation as resolved.
Show resolved Hide resolved
AwaitExpression(node) {
if (util.isTypeAssertion(node.argument)) {
// reduces the precedence of the node so the rule thinks it needs to be rapped
yeonjuan marked this conversation as resolved.
Show resolved Hide resolved
return rules.AwaitExpression({
...node,
argument: {
...node.argument,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}
return rules.AwaitExpression(node);
yeonjuan marked this conversation as resolved.
Show resolved Hide resolved
},
BinaryExpression: binaryExp,
CallExpression: callExp,
// ClassDeclaration
Expand Down
11 changes: 10 additions & 1 deletion packages/eslint-plugin/tests/rules/no-extra-parens.test.ts
Expand Up @@ -19,6 +19,7 @@ ruleTester.run('no-extra-parens', rule, {
valid: [
...batchedSingleLineTests({
code: `
async function f(arg: any) { await (arg as Promise<void>); }
(0).toString();
(function(){}) ? a() : b();
(/^a$/).test(x);
Expand Down Expand Up @@ -238,6 +239,8 @@ for (a of (b));
typeof (a);
a<import('')>((1));
new a<import('')>((1));
a<(A)>((1));
async function f(arg: any) { await ((arg as Promise<void>)); }
`,
output: `
a = b * c;
Expand All @@ -248,7 +251,8 @@ for (a of b);
typeof a;
a<import('')>(1);
new a<import('')>(1);
a<(A)>((1));
a<(A)>(1);
async function f(arg: any) { await (arg as Promise<void>); }
`,
errors: [
{
Expand Down Expand Up @@ -296,6 +300,11 @@ a<(A)>((1));
line: 10,
column: 8,
},
{
messageId: 'unexpected',
line: 11,
column: 37,
},
],
}),
...batchedSingleLineTests({
Expand Down