Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

prefer-spread

Require spread syntax instead of .apply() to pass an array as arguments

Math.max.apply(Math, values) only uses .apply() to pass an array as separate arguments, and it has to repeat Math to keep this. Math.max(...values) does the same thing and reads like a normal call.

A call is only reported if spread can replace it, so .apply() must leave this the way a plain call would. That means null or undefined for a function, and the same object for a method.

This rule is on by default in TypeScript files.

Configure

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"prefer-spread" = "off" # or "error"

Examples

Reported:

const highest = Math.max.apply(Math, values);
notify.apply(null, listeners);
logger.info.apply(logger, parts);

Not reported:

const highest = Math.max(...values);
notify(...listeners);
logger.info(...parts);

// Sets another `this`, which spread cannot do
render.apply(view, parts);
logger.info.apply(console, parts);