Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-unused-vars] don't report nested module declaration #3119

Merged
merged 1 commit into from Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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