@@ -67,6 +67,17 @@ impl Rule for NoUndef {
6767 continue ;
6868 }
6969
70+ // Skip reporting error for 'arguments' if it's in a function scope
71+ if name == "arguments"
72+ && ctx
73+ . scoping ( )
74+ . scope_ancestors ( ctx. nodes ( ) . get_node ( reference. node_id ( ) ) . scope_id ( ) )
75+ . map ( |id| ctx. scoping ( ) . scope_flags ( id) )
76+ . any ( |scope_flags| scope_flags. is_function ( ) && !scope_flags. is_arrow ( ) )
77+ {
78+ continue ;
79+ }
80+
7081 let node = ctx. nodes ( ) . get_node ( reference. node_id ( ) ) ;
7182 if !self . type_of && has_typeof_operator ( node, ctx) {
7283 continue ;
@@ -168,6 +179,10 @@ fn test() {
168179 ( "class C { static { a; function a() {} } }" , None , None ) ,
169180 ( "String;Array;Boolean;" , None , None ) ,
170181 ( "[Float16Array, Iterator]" , None , None ) , // es2025
182+ // arguments should not be reported in regular functions
183+ ( "function test() { return arguments; }" , None , None ) ,
184+ ( "var fn = function() { return arguments[0]; };" , None , None ) ,
185+ ( "const obj = { method() { return arguments.length; } };" , None , None ) ,
171186 // ("AsyncDisposableStack; DisposableStack; SuppressedError", None, None), / es2026
172187 ( "function resolve<T>(path: string): T { return { path } as T; }" , None , None ) ,
173188 ( "let xyz: NodeListOf<HTMLElement>" , None , None ) ,
@@ -210,6 +225,10 @@ fn test() {
210225 ( "toString()" , None , None ) ,
211226 ( "hasOwnProperty()" , None , None ) ,
212227 ( "export class Foo{ bar: notDefined; }; const t = r + 1;" , None , None ) ,
228+ // arguments should be reported in arrow functions (they don't have their own arguments)
229+ ( "const arrow = () => arguments;" , None , None ) ,
230+ // arguments outside functions should be reported
231+ ( "var a = arguments;" , None , None ) ,
213232 ] ;
214233
215234 Tester :: new ( NoUndef :: NAME , NoUndef :: PLUGIN , pass, fail) . test_and_snapshot ( ) ;
0 commit comments