{"record":{"id":"e618d7504ab3c87e","repo":"oxc-project/oxc","slug":"use-the-rest-parameters-instead-of-arguments","errorCode":null,"errorMessage":"Use the rest parameters instead of `arguments`.","messagePattern":"Use the rest parameters instead of `arguments`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_rest_params.rs","lineNumber":8,"sourceCode":"use crate::{AstNode, context::LintContext, rule::Rule};\nuse oxc_ast::{AstKind, AstType};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nfn prefer_rest_params_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use the rest parameters instead of `arguments`.\")\n        .with_help(\"Replace `arguments` with rest parameters (`...args`).\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferRestParams;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows the use of the `arguments` object and instead enforces the use of rest parameters.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `arguments` object does not have methods from `Array.prototype`, making it inconvenient for array-like operations.\n    /// Using rest parameters provides a more intuitive and efficient way to handle variadic arguments.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_rest_params.rs#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Change the function signature to use rest parameters: `function fn() { return arguments.length; }` becomes `function fn(...args) { return args.length; }`.","Replace `Array.prototype.slice.call(arguments)` with direct use of the rest array (it is already a real Array).","If `arguments` is genuinely required (e.g. forwarding in strict-mode-agnostic code), suppress with `// oxlint-disable-next-line prefer-rest-params`.","Disable the rule project-wide in `.oxlintrc.json` if you maintain ES5 output."],"exampleFix":"// before\nfunction sum() {\n  let total = 0;\n  for (let i = 0; i < arguments.length; i++) total += arguments[i];\n  return total;\n}\n\n// after\nfunction sum(...args) {\n  return args.reduce((total, n) => total + n, 0);\n}","handlingStrategy":"validation","validationCode":"# surface `arguments` usage before it hits CI\nrg -n '\\barguments\\b' src/ --glob '!*.min.js'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write new variadic APIs with `...args` from the start; rest params are real arrays.","Remember `arguments` does not exist in arrow functions — referencing it there reads the enclosing function's object or throws.","When porting ES5 code, convert `arguments`-based helpers in the same pass and let oxlint confirm no references remain."],"tags":["eslint","oxlint","es6","modernization","lint"],"backgroundTag":"prefer-rest-params","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}