{"record":{"id":"8729bf005576b01b","repo":"oxc-project/oxc","slug":"bad-array-method-on-arguments","errorCode":null,"errorMessage":"Bad array method on `arguments`.","messagePattern":"Bad array method on `arguments`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/bad_array_method_on_arguments.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, MemberExpressionKind};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn bad_array_method_on_arguments_diagnostic(method_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Bad array method on `arguments`.\")\n        .with_help(format!(\n            \"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.\"\n        ))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct BadArrayMethodOnArguments;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule applies when an array method is called on the arguments object itself.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The [arguments object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)\n    /// is not an array, but an array-like object. It should be converted to a real array before calling an array method.","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/bad_array_method_on_arguments.rs#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use rest parameters — the modern replacement: 'function f(...args) { return args.pop(); }'","Convert once at the top: 'const args = Array.from(arguments);'","When only iterating, borrow without copying: 'Array.prototype.forEach.call(arguments, fn)'"],"exampleFix":"// before\nfunction lastArg() {\n  return arguments[arguments.length - 1];\n}\nfunction dropLast() {\n  arguments.pop(); // TypeError at runtime\n}\n\n// after\nfunction lastArg(...args) {\n  return args[args.length - 1];\n}\nfunction dropLast(...args) {\n  args.pop();\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n\"rules\": { \"oxc/bad-array-method-on-arguments\": \"error\" }\n\nnpx oxlint -c .oxlintrc.json --deny-warning .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write new variadic functions with rest parameters (...args) so `arguments` never appears","When touching legacy `arguments` code, convert the function to rest params in the same commit","Add a unit test that exercises each refactored variadic path — the underlying bug throws only when the line runs"],"tags":["oxc","javascript","arguments","array-methods","runtime-error","oxlint"],"backgroundTag":"array-method-on-arguments","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}