Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-extra-parens] handle type assertion in extends clause#5901

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 5 commits intotypescript-eslint:mainfromyeonjuan:fix/#5899
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletionspackages/eslint-plugin/src/rules/no-extra-parens.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,8 +141,30 @@ export default util.createRule<Options, MessageIds>({
},
BinaryExpression: binaryExp,
CallExpression: callExp,
// ClassDeclaration
// ClassExpression
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);
},
ClassExpression(node) {
if (node.superClass?.type === AST_NODE_TYPES.TSAsExpression) {
return rules.ClassExpression({
...node,
superClass: {
...node.superClass,
type: AST_NODE_TYPES.SequenceExpression as any,
},
});
}
return rules.ClassExpression(node);
},
ConditionalExpression(node) {
// reduces the precedence of the node so the rule thinks it needs to be wrapped
if (util.isTypeAssertion(node.test)) {
Expand Down
32 changes: 32 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-extra-parens.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,6 +141,10 @@ 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 {}
class Foo extends (Bar as any) {}
const foo = class {};
const foo = class extends (Bar as any) {}
`,
parserOptions: {
ecmaFeatures: {
Expand DownExpand Up@@ -254,6 +258,10 @@ 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)) {}
class Foo extends (Bar) {}
const foo = class extends ((Bar as any)) {}
const foo = class extends (Bar) {}
`,
output: `
a = b * c;
Expand All@@ -267,6 +275,10 @@ 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) {}
class Foo extends Bar {}
const foo = class extends (Bar as any) {}
const foo = class extends Bar {}
`,
errors: [
{
Expand DownExpand Up@@ -324,6 +336,26 @@ async function f(arg: any) { await (arg as Promise<void>); }
line: 12,
column: 37,
},
{
messageId: 'unexpected',
line: 13,
column: 20,
},
{
messageId: 'unexpected',
line: 14,
column: 19,
},
{
messageId: 'unexpected',
line: 15,
column: 28,
},
{
messageId: 'unexpected',
line: 16,
column: 27,
},
],
}),
...batchedSingleLineTests({
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp