Skip to content

Commit 29ad42f

Browse files
committed
fix(typescript/prefer-namespace-keyword): skip nested TSModuleDeclarations
1 parent c167dfa commit 29ad42f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ impl Rule for PreferNamespaceKeyword {
6161
return;
6262
}
6363

64+
// Ignore nested `TSModuleDeclaration`s
65+
// e.g. the 2 inner `TSModuleDeclaration`s in `module A.B.C {}`
66+
if let AstKind::TSModuleDeclaration(_) = ctx.nodes().parent_kind(node.id()) {
67+
return;
68+
}
69+
6470
let Some(offset) = ctx.find_next_token_from(module.span.start, "module") else { return };
6571

6672
ctx.diagnostic_with_fix(prefer_namespace_keyword_diagnostic(module.span), |fixer| {
@@ -134,6 +140,11 @@ fn test() {
134140
None,
135141
),
136142
("declare /* module */ module foo {}", "declare /* module */ namespace foo {}", None),
143+
(
144+
"declare module X.Y.module { x = 'module'; }",
145+
"declare namespace X.Y.module { x = 'module'; }",
146+
None,
147+
),
137148
];
138149

139150
Tester::new(PreferNamespaceKeyword::NAME, PreferNamespaceKeyword::PLUGIN, pass, fail)

0 commit comments

Comments
 (0)