@@ -57,6 +57,15 @@ impl Rule for NoVar {
5757 if let AstKind :: VariableDeclaration ( dec) = node. kind ( )
5858 && dec. kind == VariableDeclarationKind :: Var
5959 {
60+ // Skip TypeScript ambient declarations (declare global/module/namespace)
61+ if ctx
62+ . nodes ( )
63+ . ancestors ( node. id ( ) )
64+ . any ( |ancestor| matches ! ( ancestor. kind( ) , AstKind :: TSModuleDeclaration ( module) if module. declare || module. kind. is_global( ) ) )
65+ {
66+ return ;
67+ }
68+
6069 let is_written_to = dec. declarations . iter ( ) . any ( |v| is_written_to ( & v. id , ctx) ) ;
6170 let var_offset = ctx. find_next_token_from ( dec. span . start , "var" ) . unwrap ( ) ;
6271 let var_start = dec. span . start + var_offset;
@@ -119,7 +128,13 @@ fn is_written_to(binding_pat: &BindingPattern, ctx: &LintContext) -> bool {
119128fn test ( ) {
120129 use crate :: tester:: Tester ;
121130
122- let pass = vec ! [ ( "const JOE = 'schmoe';" , None ) , ( "let moo = 'car';" , None ) ] ;
131+ let pass = vec ! [
132+ ( "let moo = 'car';" , None ) ,
133+ ( "const JOE = 'schmoe';" , None ) ,
134+ ( "declare module 'testModule' { var x: string; }" , None ) ,
135+ ( "declare namespace MyNamespace { var y: number; }" , None ) ,
136+ ( "declare global { var __TEST_DECLARE_GLOBAL__: boolean | undefined; }" , None ) ,
137+ ] ;
123138
124139 let fail = vec ! [
125140 ( "var foo = bar;" , None ) ,
0 commit comments