diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index 7d8eff0b9e2..e9b73370966 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -20,6 +20,12 @@ type Options = [ }, ]; +const allowedFunctionVariableDefTypes = new Set([ + AST_NODE_TYPES.TSCallSignatureDeclaration, + AST_NODE_TYPES.TSFunctionType, + AST_NODE_TYPES.TSMethodSignature, +]); + export default util.createRule({ name: 'no-shadow', meta: { @@ -147,8 +153,8 @@ export default util.createRule({ return false; } - return variable.defs.every( - def => def.node.type === AST_NODE_TYPES.TSFunctionType, + return variable.defs.every(def => + allowedFunctionVariableDefTypes.has(def.node.type), ); } 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 d55e85b3d8f..854154ff096 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 @@ -145,6 +145,27 @@ type Fn = (Foo: string) => typeof Foo; Foo: 'writable', }, }, + // https://github.com/typescript-eslint/typescript-eslint/issues/6098 + { + code: ` +const arg = 0; + +interface Test { + (arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, + { + code: ` +const arg = 0; + +interface Test { + p1(arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: true }], + }, // https://github.com/typescript-eslint/typescript-eslint/issues/2724 { code: ` @@ -525,6 +546,48 @@ type Fn = (Foo: string) => typeof Foo; }, ], }, + + // https://github.com/typescript-eslint/typescript-eslint/issues/6098 + { + code: ` +const arg = 0; + +interface Test { + (arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + errors: [ + { + messageId: 'noShadow', + data: { + name: 'arg', + shadowedLine: 2, + shadowedColumn: 7, + }, + }, + ], + }, + { + code: ` +const arg = 0; + +interface Test { + p1(arg: string): typeof arg; +} + `, + options: [{ ignoreFunctionTypeParameterNameValueShadow: false }], + errors: [ + { + messageId: 'noShadow', + data: { + name: 'arg', + shadowedLine: 2, + shadowedColumn: 7, + }, + }, + ], + }, { code: ` import type { foo } from './foo';