AphrodyBun GitHub

Runtime docs · Linter · Rules

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

Reported:

function total() {
  return arguments.reduce((sum, price) => sum + price, 0);
}

Not reported:

function total(...prices) {
  return prices.reduce((sum, price) => sum + price, 0);
}

function legacyTotal() {
  return Array.from(arguments).reduce((sum, price) => sum + price, 0);
}