@@ -133,7 +133,6 @@ impl Rule for NoNamespace {
133133 }
134134 }
135135
136- #[ expect( clippy:: cast_possible_truncation) ]
137136 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
138137 let AstKind :: TSModuleDeclaration ( declaration) = node. kind ( ) else {
139138 return ;
@@ -156,16 +155,14 @@ impl Rule for NoNamespace {
156155 return ;
157156 }
158157
159- let declaration_code = declaration. span . source_text ( ctx. source_text ( ) ) ;
160-
161158 let span = match declaration. kind {
162159 TSModuleDeclarationKind :: Global => None , // handled above
163- TSModuleDeclarationKind :: Module => declaration_code
164- . find ( "module" )
165- . map ( |i| Span :: sized ( declaration. span . start + i as u32 , 6 ) ) ,
166- TSModuleDeclarationKind :: Namespace => declaration_code
167- . find ( "namespace" )
168- . map ( |i| Span :: sized ( declaration. span . start + i as u32 , 9 ) ) ,
160+ TSModuleDeclarationKind :: Module => ctx
161+ . find_next_token_from ( declaration . span . start , "module" )
162+ . map ( |i| Span :: sized ( declaration. span . start + i, 6 ) ) ,
163+ TSModuleDeclarationKind :: Namespace => ctx
164+ . find_next_token_from ( declaration . span . start , "namespace" )
165+ . map ( |i| Span :: sized ( declaration. span . start + i, 9 ) ) ,
169166 } ;
170167 if let Some ( span) = span {
171168 ctx. diagnostic ( no_namespace_diagnostic ( span) ) ;
@@ -381,6 +378,8 @@ fn test() {
381378 }" ,
382379 Some ( serde_json:: json!( [ { "allowDeclarations" : true } ] ) ) ,
383380 ) ,
381+ ( "declare /* module */ module foo {}" , None ) ,
382+ ( "declare /* namespace */ namespace foo {}" , None ) ,
384383 ] ;
385384
386385 Tester :: new ( NoNamespace :: NAME , NoNamespace :: PLUGIN , pass, fail) . test_and_snapshot ( ) ;
0 commit comments