Skip to content
Permalink
Browse files

fix(eslint-plugin): [no-unused-vars] fix false positives for duplicat…

…ed names in namespaces (#2659)
  • Loading branch information
mbpreble committed Oct 12, 2020
1 parent 77732a2 commit 0d696c72c5c9c3446902a63509d499ee95483e81
@@ -1,7 +1,7 @@
import {
TSESTree,
TSESLint,
AST_NODE_TYPES,
TSESLint,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { PatternVisitor } from '@typescript-eslint/scope-manager';
import baseRule from 'eslint/lib/rules/no-unused-vars';
@@ -327,18 +327,22 @@ export default util.createRule<Options, MessageIds>({
break;
}

const scope = context.getScope();
const { variableScope } = scope;
if (variableScope !== scope) {
for (const id of identifiers) {
const superVar = variableScope.set.get(id.name);
if (superVar) {
superVar.eslintUsed = true;
}
}
} else {
for (const id of identifiers) {
context.markVariableAsUsed(id.name);
let scope = context.getScope();
const shouldUseUpperScope = [
AST_NODE_TYPES.TSModuleDeclaration,
AST_NODE_TYPES.TSDeclareFunction,
].includes(node.type);

if (scope.variableScope !== scope) {
scope = scope.variableScope;
} else if (shouldUseUpperScope && scope.upper) {
scope = scope.upper;
}

for (const id of identifiers) {
const superVar = scope.set.get(id.name);
if (superVar) {
superVar.eslintUsed = true;
}
}
}
@@ -886,6 +886,20 @@ export declare namespace Foo {
}
}
`,
{
code: `
declare namespace A {
export interface A {}
}
`,
filename: 'foo.d.ts',
},
{
code: `
declare function A(A: string): string;
`,
filename: 'foo.d.ts',
},
],

invalid: [

0 comments on commit 0d696c7

Please sign in to comment.
You can’t perform that action at this time.