diff --git a/packages/eslint-plugin/src/rules/no-unused-vars.ts b/packages/eslint-plugin/src/rules/no-unused-vars.ts index 79709e1df1e..2e6633afc57 100644 --- a/packages/eslint-plugin/src/rules/no-unused-vars.ts +++ b/packages/eslint-plugin/src/rules/no-unused-vars.ts @@ -264,6 +264,23 @@ export default util.createRule({ 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', diff --git a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts index eaf59a48571..c5b5ef1887f 100644 --- a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts @@ -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