Skip to content

Commit fa7400a

Browse files
committed
fix(linter/no-undef): false positive with arguments in functions (#13763)
fixes #13762
1 parent 0b48186 commit fa7400a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

crates/oxc_linter/src/rules/eslint/no_undef.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

crates/oxc_linter/src/snapshots/eslint_no_undef.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,15 @@ source: crates/oxc_linter/src/tester.rs
174174
1export class Foo{ bar: notDefined; }; const t = r + 1;
175175
· ─
176176
╰────
177+
178+
eslint(no-undef): 'arguments' is not defined.
179+
╭─[no_undef.tsx:1:21]
180+
1const arrow = () => arguments;
181+
· ─────────
182+
╰────
183+
184+
eslint(no-undef): 'arguments' is not defined.
185+
╭─[no_undef.tsx:1:9]
186+
1var a = arguments;
187+
· ─────────
188+
╰────

0 commit comments

Comments
 (0)