menu
no-accumulating-spread
Disallow repeated accumulator spreads within iterations
Spreading an accumulator into its replacement copies every value accumulated so far. Repeating the replacement in a loop or reduction callback can make total copying grow quadratically. Instead, you SHOULD use an operation that extends storage without rebuilding the preceding values.
Aliasing can make in-place mutation observably different, so the diagnostic requires a manual rewrite.
Reported
1function copy(source: int32[]): int32[] {2 let output: int32[] = [];3 for (const value of source) {4 output = [...output, value];5 }6 7 return output;8}Accepted
1function copy(source: int32[]): int32[] {2 let output: int32[] = [];3 for (const value of source) {4 output.push(value);5 }6 7 return output;8}