.apply passes an array of arguments where spread syntax would
What it finds
fn.apply(null, args) and obj.method.apply(obj, args) were the way to call a function with an array of arguments before spread syntax; fn(...args) and obj.method(...args) say the same directly.
Reported are .apply calls with two arguments whose first is the this a plain call passes: undefined or null for a function name, and the object, written the same way, for a method. The fix writes the call with a spread; it is unsafe, as apply also accepts array-like objects that are not iterable, which spread rejects.
From the rule's source, apply_for_spread.rs.
export function run(fn: (...a: number[]) => void, args: number[], obj: { m(...a: number[]): void }) { fn.apply(null, args);tx0 reports: .apply spreads an array of arguments obj.m.apply(obj, args);tx0 reports: .apply spreads an array of arguments fn.apply(obj, args);} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:apply-for-spread" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:apply-for-spread] reason="..."tx0 explain tx0/ts:apply-for-spread shows the same in the terminal. Found a false positive? Report it.