Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unused-vars] don't report nested module decla…
Browse files Browse the repository at this point in the history
…ration (#3119)
  • Loading branch information
armano2 committed Mar 1, 2021
1 parent 0336c79 commit 4ca5888
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/eslint-plugin/src/rules/no-unused-vars.ts
Expand Up @@ -264,6 +264,23 @@ export default util.createRule<Options, MessageIds>({
markDeclarationChildAsUsed(node);
},

// module declaration in module declaration should not report unused vars error
// this is workaround as this change should be done in better way
'TSModuleDeclaration > TSModuleDeclaration'(
node: TSESTree.TSModuleDeclaration,
): void {
if (node.id.type === AST_NODE_TYPES.Identifier) {
let scope = context.getScope();
if (scope.upper) {
scope = scope.upper;
}
const superVar = scope.set.get(node.id.name);
if (superVar) {
superVar.eslintUsed = true;
}
}
},

// children of a namespace that is a child of a declared namespace are auto-exported
[ambientDeclarationSelector(
'TSModuleDeclaration[declare = true] > TSModuleBlock TSModuleDeclaration > TSModuleBlock',
Expand Down
Expand Up @@ -688,6 +688,13 @@ export { Foo };
`
export namespace Foo {
export const item: Foo = 1;
}
`,
`
export namespace foo.bar {
export interface User {
name: string;
}
}
`,
// exported self-referencing types
Expand Down

0 comments on commit 4ca5888

Please sign in to comment.