oxc-project/oxc · warning · OxcDiagnostic

Use the rest parameters instead of `arguments`.

Error message

Use the rest parameters instead of `arguments`.

What it means

oxlint `eslint/prefer-rest-params`: the legacy `arguments` object was referenced inside a function, and the rule (per its doc block, 'Disallows the use of the `arguments` object') wants ES6 rest parameters instead. The diagnostic at prefer_rest_params.rs:8 fires on the `arguments` identifier reference. Rest parameters are preferred because they are real arrays and work in arrow functions, where `arguments` does not exist.

Source

Thrown at crates/oxc_linter/src/rules/eslint/prefer_rest_params.rs:8

use crate::{AstNode, context::LintContext, rule::Rule};
use oxc_ast::{AstKind, AstType};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

fn prefer_rest_params_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use the rest parameters instead of `arguments`.")
        .with_help("Replace `arguments` with rest parameters (`...args`).")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows the use of the `arguments` object and instead enforces the use of rest parameters.
    ///
    /// ### Why is this bad?
    ///
    /// The `arguments` object does not have methods from `Array.prototype`, making it inconvenient for array-like operations.
    /// Using rest parameters provides a more intuitive and efficient way to handle variadic arguments.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Change the function signature to use rest parameters: `function fn() { return arguments.length; }` becomes `function fn(...args) { return args.length; }`.
  2. Replace `Array.prototype.slice.call(arguments)` with direct use of the rest array (it is already a real Array).
  3. If `arguments` is genuinely required (e.g. forwarding in strict-mode-agnostic code), suppress with `// oxlint-disable-next-line prefer-rest-params`.
  4. Disable the rule project-wide in `.oxlintrc.json` if you maintain ES5 output.

Example fix

// before
function sum() {
  let total = 0;
  for (let i = 0; i < arguments.length; i++) total += arguments[i];
  return total;
}

// after
function sum(...args) {
  return args.reduce((total, n) => total + n, 0);
}
Defensive patterns

Strategy: validation

Validate before calling

# surface `arguments` usage before it hits CI
rg -n '\barguments\b' src/ --glob '!*.min.js'

Prevention

When it happens

Trigger: Any identifier reference to `arguments` (e.g. `arguments.length`, `arguments[0]`, `Array.prototype.slice.call(arguments)`) reachable in a visited function body. The rule visits the AST looking for the `arguments` IdentifierReference.

Common situations: ES5-era variadic helpers copied into a modern codebase; code inside arrow functions that references an outer `arguments` (confusing even when legal); babel-compiled output committed to source.

Related errors


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