oxc/bad-array-method-on-arguments
Disallow calling array methods on the arguments object
arguments looks like an array because it has a length and numbered items. It isn't one, so it doesn't have map, filter, join or slice. Calling one of them throws TypeError: arguments.map is not a function.
Use a rest parameter, which is a real array, or copy arguments into an array first.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"oxc/bad-array-method-on-arguments" = "error" # or "warn"Examples#
example.js1 problem
function total() {
return arguments.reduceBad array method on arguments.((sum, price) => sum + price, 0);
}example.jsNo problems
function total(...prices) {
return prices.reduce((sum, price) => sum + price, 0);
}
function legacyTotal() {
return Array.from(arguments).reduce((sum, price) => sum + price, 0);
}