1- use oxc_ast:: {
2- AstKind ,
3- ast:: { TSModuleDeclarationKind , TSModuleDeclarationName } ,
4- } ;
1+ use oxc_ast:: { AstKind , ast:: TSModuleDeclarationName } ;
52use oxc_diagnostics:: OxcDiagnostic ;
63use oxc_macros:: declare_oxc_lint;
74use oxc_span:: Span ;
@@ -141,6 +138,8 @@ impl Rule for NoNamespace {
141138 return ;
142139 }
143140
141+ // Ignore nested `TSModuleDeclaration`s
142+ // e.g. the 2 inner `TSModuleDeclaration`s in `module A.B.C {}`
144143 if let AstKind :: TSModuleDeclaration ( _) = ctx. nodes ( ) . parent_kind ( node. id ( ) ) {
145144 return ;
146145 }
@@ -151,17 +150,12 @@ impl Rule for NoNamespace {
151150 return ;
152151 }
153152
154- let span = match declaration. kind {
155- TSModuleDeclarationKind :: Module => ctx
156- . find_next_token_from ( declaration. span . start , "module" )
157- . map ( |i| Span :: sized ( declaration. span . start + i, 6 ) ) ,
158- TSModuleDeclarationKind :: Namespace => ctx
159- . find_next_token_from ( declaration. span . start , "namespace" )
160- . map ( |i| Span :: sized ( declaration. span . start + i, 9 ) ) ,
161- } ;
162- if let Some ( span) = span {
163- ctx. diagnostic ( no_namespace_diagnostic ( span) ) ;
164- }
153+ let keyword = declaration. kind . as_str ( ) ;
154+ let mut span_start = declaration. span . start ;
155+ span_start += ctx. find_next_token_from ( span_start, keyword) . unwrap ( ) ;
156+ #[ expect( clippy:: cast_possible_truncation) ]
157+ let span = Span :: sized ( span_start, keyword. len ( ) as u32 ) ;
158+ ctx. diagnostic ( no_namespace_diagnostic ( span) ) ;
165159 }
166160
167161 fn should_run ( & self , ctx : & ContextHost ) -> bool {
0 commit comments