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 type assertion in extends clause #5901

Merged
merged 5 commits into from Oct 30, 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: 12 additions & 1 deletion packages/eslint-plugin/src/rules/no-extra-parens.ts
Expand Up @@ -141,7 +141,18 @@ export default util.createRule<Options, MessageIds>({
},
BinaryExpression: binaryExp,
CallExpression: callExp,
// ClassDeclaration
ClassDeclaration(node) {
if (node.superClass?.type === AST_NODE_TYPES.TSAsExpression) {
return rules.ClassDeclaration({
...node,
superClass: {
...node.superClass,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}
return rules.ClassDeclaration(node);
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
},
// ClassExpression
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
ConditionalExpression(node) {
// reduces the precedence of the node so the rule thinks it needs to be wrapped
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tests/rules/no-extra-parens.test.ts
Expand Up @@ -141,6 +141,7 @@ t.true((me.get as SinonStub).calledWithExactly('/foo', other));
t.true((<SinonStub>me.get).calledWithExactly('/foo', other));
(requestInit.headers as Headers).get('Cookie');
(<Headers> requestInit.headers).get('Cookie');
class Foo extends (Bar as any) {}
`,
parserOptions: {
ecmaFeatures: {
Expand Down Expand Up @@ -254,6 +255,7 @@ new a<import('')>((1));
a<(A)>((1));
async function f(arg: Promise<any>) { await (arg); }
async function f(arg: any) { await ((arg as Promise<void>)); }
class Foo extends ((Bar as any)) {}
`,
output: `
a = b * c;
Expand All @@ -267,6 +269,7 @@ new a<import('')>(1);
a<(A)>(1);
async function f(arg: Promise<any>) { await arg; }
async function f(arg: any) { await (arg as Promise<void>); }
class Foo extends (Bar as any) {}
`,
errors: [
{
Expand Down Expand Up @@ -324,6 +327,11 @@ async function f(arg: any) { await (arg as Promise<void>); }
line: 12,
column: 37,
},
{
messageId: 'unexpected',
line: 13,
column: 20,
},
],
}),
...batchedSingleLineTests({
Expand Down