oxc-project/oxc · error · OxcDiagnostic

Bad array method on `arguments`.

Error message

Bad array method on `arguments`.

What it means

Diagnostic from oxlint rule oxc/bad-array-method-on-arguments (correctness category). The `arguments` object is array-like (has length and indices) but carries none of Array.prototype's methods, so arguments.pop(), arguments.forEach(fn) and friends throw 'TypeError: arguments.pop is not a function' the moment the line executes. The rule catches these dead-on-arrival calls statically and suggests rest parameters or converting to a real array.

Source

Thrown at crates/oxc_linter/src/rules/oxc/bad_array_method_on_arguments.rs:9

use oxc_ast::{AstKind, MemberExpressionKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule};

fn bad_array_method_on_arguments_diagnostic(method_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Bad array method on `arguments`.")
        .with_help(format!(
            "The `arguments` object does not have a `{method_name}()` method. If you intended to use an array method, consider using rest parameters instead or converting the `arguments` object to an array."
        ))
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct BadArrayMethodOnArguments;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// This rule applies when an array method is called on the arguments object itself.
    ///
    /// ### Why is this bad?
    ///
    /// The [arguments object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)
    /// is not an array, but an array-like object. It should be converted to a real array before calling an array method.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use rest parameters — the modern replacement: 'function f(...args) { return args.pop(); }'
  2. Convert once at the top: 'const args = Array.from(arguments);'
  3. When only iterating, borrow without copying: 'Array.prototype.forEach.call(arguments, fn)'

Example fix

// before
function lastArg() {
  return arguments[arguments.length - 1];
}
function dropLast() {
  arguments.pop(); // TypeError at runtime
}

// after
function lastArg(...args) {
  return args[args.length - 1];
}
function dropLast(...args) {
  args.pop();
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
"rules": { "oxc/bad-array-method-on-arguments": "error" }

npx oxlint -c .oxlintrc.json --deny-warning .

Prevention

When it happens

Trigger: A member-expression call on the identifier `arguments` whose method name is an Array.prototype method — pop, push, shift, forEach, map, filter, slice, indexOf, ... — inside code where `arguments` is in scope (plain functions; arrow functions have no own `arguments`, so occurrences there usually reference an outer function's object). The diagnostic's help embeds the missing method name.

Common situations: Pre-ES5/ES5-era variadic functions being modernized piecemeal; refactors that replaced Array.prototype.slice.call(arguments) plumbing with a direct method call by mistake; copy-paste from array code into an arguments-based function.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/8729bf005576b01b. Report an issue: GitHub.