From 6e02253a93e48d6dd0055ea3f7c277b7205091dc Mon Sep 17 00:00:00 2001 From: Mark de Dios Date: Mon, 18 Sep 2023 18:05:15 -0700 Subject: [PATCH 1/4] Add test for factory generating class functionn with generic type --- .../tests/rules/no-shadow/no-shadow.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts index ae00139d9821..c2e039fb2cd9 100644 --- a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts +++ b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts @@ -221,6 +221,17 @@ export class Wrapper { return new Wrapper(wrapped); } } + `, + ` + function makeA() { + return class A { + constructor(public value: T) { } + + static make(value: T) { + return new A(value); + } + } + } `, { // https://github.com/typescript-eslint/typescript-eslint/issues/3862 From 34d5905b9a7dc73dca3e88d22588d6912fecea3e Mon Sep 17 00:00:00 2001 From: Mark de Dios Date: Wed, 4 Oct 2023 17:45:20 -0700 Subject: [PATCH 2/4] Rename isGenericOfClassDecl to isGenericOfClass, check for class expression in function --- packages/eslint-plugin/src/rules/no-shadow.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index e8dc7a260f8d..3164b9cf794a 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -199,7 +199,7 @@ export default util.createRule({ return methodDefinition.static; } - function isGenericOfClassDecl(variable: TSESLint.Scope.Variable): boolean { + function isGenericOfClass(variable: TSESLint.Scope.Variable): boolean { if (!('isTypeVariable' in variable)) { // this shouldn't happen... return false; @@ -224,16 +224,17 @@ export default util.createRule({ return false; } const classDecl = typeParameterDecl.parent; - return classDecl?.type === AST_NODE_TYPES.ClassDeclaration; + return ( + classDecl?.type === AST_NODE_TYPES.ClassDeclaration || + classDecl?.type === AST_NODE_TYPES.ClassExpression + ); } function isGenericOfAStaticMethodShadow( variable: TSESLint.Scope.Variable, shadowed: TSESLint.Scope.Variable, ): boolean { - return ( - isGenericOfStaticMethod(variable) && isGenericOfClassDecl(shadowed) - ); + return isGenericOfStaticMethod(variable) && isGenericOfClass(shadowed); } function isImportDeclaration( From 08feeaa6f7d1c083b6c80f983dc496a2434bc7aa Mon Sep 17 00:00:00 2001 From: Mark de Dios Date: Wed, 4 Oct 2023 18:15:24 -0700 Subject: [PATCH 3/4] Apply eslint fixer on no shadow test class expression test case --- .../tests/rules/no-shadow/no-shadow.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts index c2e039fb2cd9..d32ad2cc938c 100644 --- a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts +++ b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts @@ -223,15 +223,15 @@ export class Wrapper { } `, ` - function makeA() { - return class A { - constructor(public value: T) { } +function makeA() { + return class A { + constructor(public value: T) { } - static make(value: T) { - return new A(value); - } - } + static make(value: T) { + return new A(value); } + } +} `, { // https://github.com/typescript-eslint/typescript-eslint/issues/3862 From 0cdc6d500a855bd84c6f81a46822f4df3fda2b07 Mon Sep 17 00:00:00 2001 From: Mark de Dios Date: Mon, 9 Oct 2023 20:25:28 -0700 Subject: [PATCH 4/4] Apply yarn lint-fix --- .../eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts index d32ad2cc938c..277233d88d68 100644 --- a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts +++ b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts @@ -225,12 +225,12 @@ export class Wrapper { ` function makeA() { return class A { - constructor(public value: T) { } + constructor(public value: T) {} static make(value: T) { return new A(value); } - } + }; } `, {