combinedPushes
Reports consecutive array.push() calls that could be combined into a single call.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
Multiple consecutive .push() calls on the same array can be combined into a single call.
Using .push(a, b, c) is more concise than separate .push(a), .push(b), .push(c) calls.
Examples
Section titled “Examples”const const items: string[]
items: string[] = [];
const items: string[]
items.Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push("a");const items: string[]
items.Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push("b");const items: string[]
items.Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push("c");const const items: string[]
items: string[] = [];
const items: string[]
items.Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push("a", "b", "c");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer the visual separation of individual .push() calls, or if you’re intentionally pushing items one at a time for debugging or other purposes, you can disable this rule.
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/prefer-single-call