Skip to content

Commit

Permalink
fix(eslint-plugin): [no-shadow] add call and method signatures to `ig…
Browse files Browse the repository at this point in the history
…noreFunctionTypeParameterNameValueShadow` (#6129)
  • Loading branch information
JoshuaKGoldberg committed Dec 2, 2022
1 parent 1dba257 commit 9d58b6b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/eslint-plugin/src/rules/no-shadow.ts
Expand Up @@ -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<Options, MessageIds>({
name: 'no-shadow',
meta: {
Expand Down Expand Up @@ -147,8 +153,8 @@ export default util.createRule<Options, MessageIds>({
return false;
}

return variable.defs.every(
def => def.node.type === AST_NODE_TYPES.TSFunctionType,
return variable.defs.every(def =>
allowedFunctionVariableDefTypes.has(def.node.type),
);
}

Expand Down
63 changes: 63 additions & 0 deletions packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts
Expand Up @@ -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: `
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 9d58b6b

Please sign in to comment.