oxc/bad-array-method-on-arguments Correctness
What it does
This rule applies when an array method is called on the arguments object itself.
Why is this bad?
The arguments object is not an array, but an array-like object. It should be converted to a real array before calling an array method. Otherwise, a TypeError exception will be thrown because of the non-existent method.
Examples
Examples of incorrect code for this rule:
javascript
function add(x, y) {
return x + y;
}
function sum() {
return arguments.reduce(add, 0);
}
Examples of correct code for this rule:
javascript
function add(x, y) {
return x + y;
}
function sum(...args) {
return args.reduce(add, 0);
}
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny oxc/bad-array-method-on-arguments
json
{
"rules": {
"oxc/bad-array-method-on-arguments": "error"
}
}