Skip to content

prefer-spread

Reports f.apply(undefined, args), f.apply(null, args), o.m.apply(o, args) and o['m'].apply(o, args), where the first argument is null, undefined, or the same object that the method is read from. f.apply(this, args), o.m.apply(p, args) with another object, and an array literal or a spread (...args) as the arguments are not reported.

When the call keeps the same this, apply only spreads an array into arguments, which the spread syntax says directly: f(...args) and o.m(...args). The apply form needs the reader to know the first argument is ignored.

To fix, write the call with ...args.

Reported
...
function f() {
...
}
f.apply(undefined, b);
f.apply(null, [1]);
o[m].apply(o, b);
function g() {
let d;
...
js:
lint:
rules:
prefer-spread: warn # off (default), warn, error

Enabled by the presets: js/typescript-eslint-recommended.

Suppress one line with sudsy-disable-next-line prefer-spread in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint prefer-spread full