prefer-spread

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

warn by default

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#

example.js3 problems
const highest = Math.max.apply(Math, values);
notify.apply(null, listeners);
logger.info.apply(logger, parts);
example.jsNo problems
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);