Skip to content

No Variadic Spread

Error
small-rules/no-variadic-spread

Disallow spreading a potentially unbounded array into a variadic call, because every element becomes a stack-allocated argument.

Diagnostic Messages

noVariadicSpread
Spreading an array into {{method}}() passes every element as its own stack argument, so a large array throws 'RangeError: Maximum call stack size exceeded'. Iterate the array instead.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-variadic-spread": "error"
}
}

Examples

Spreading an array into push()
target.push(...source);
Pushing elements one at a time
for (const item of source) target.push(item);