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( 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..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 @@ -220,6 +220,17 @@ export class Wrapper { static create(wrapped: Wrapped) { return new Wrapper(wrapped); } +} + `, + ` +function makeA() { + return class A { + constructor(public value: T) {} + + static make(value: T) { + return new A(value); + } + }; } `, {