menu

prefer-single-call

Combine consecutive Array.push or Array.unshift calls

Consecutive calls that append or prepend values to the same array repeat dispatch and capacity work. Instead, you SHOULD pass all values to one push or unshift call.

Calls are combined only when the arguments cannot observe the intermediate array state.

Reported

1function append(values: int32[]): void {2    values.push(1);3    values.push(2);4}

Accepted

1function append(values: int32[]): void {2    values.push(1, 2);3}