diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index 6a3605e79b8e..0e1f87149608 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -22,6 +22,10 @@ const allowedFunctionVariableDefTypes = new Set([ AST_NODE_TYPES.TSCallSignatureDeclaration, AST_NODE_TYPES.TSFunctionType, AST_NODE_TYPES.TSMethodSignature, + AST_NODE_TYPES.TSEmptyBodyFunctionExpression, + AST_NODE_TYPES.TSDeclareFunction, + AST_NODE_TYPES.TSConstructSignatureDeclaration, + AST_NODE_TYPES.TSConstructorType, ]); export default createRule({ 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 8b68d4dd08f4..6dd82ef35747 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 @@ -203,6 +203,120 @@ interface Test { }, { code: ` +const arg = 0; + +declare function test(arg: string): typeof arg; + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` +const arg = 0; + +declare const test: (arg: string) => typeof arg; + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` +const arg = 0; + +declare class Test { + p1(arg: string): typeof arg; +} + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` +const arg = 0; + +declare const Test: { + new (arg: string): typeof arg; +}; + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` +const arg = 0; + +type Bar = new (arg: number) => typeof arg; + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` +const arg = 0; + +declare namespace Lib { + function test(arg: string): typeof arg; +} + `, + errors: [ + { + data: { + name: 'arg', + shadowedColumn: 7, + shadowedLine: 2, + }, + messageId: 'noShadow', + }, + ], + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + }, + { + code: ` import type { foo } from './foo'; function doThing(foo: number) {} `, @@ -617,6 +731,60 @@ const arg = 0; interface Test { p1(arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +declare function test(arg: string): typeof arg; + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +declare const test: (arg: string) => typeof arg; + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +declare class Test { + p1(arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +declare const Test: { + new (arg: string): typeof arg; +}; + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +type Bar = new (arg: number) => typeof arg; + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +declare namespace Lib { + function test(arg: string): typeof arg; } `, options: [{ ignoreFunctionTypeParameterNameValueShadow: true }],