no-unnecessary-array-splice-count

March 27, 2026 ยท View on GitHub

๐Ÿ“ Disallow using .length or Infinity as the deleteCount or skipCount argument of Array#{splice,toSpliced}().

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

When calling Array#splice(start, deleteCount) and Array#toSpliced(start, skipCount), omitting the deleteCount and skipCount argument will delete or skip all elements after start. Using .length or Infinity is unnecessary.

Examples

// โŒ
const foo = array.toSpliced(1, string.length);

// โœ…
const foo = array.toSpliced(1);
// โŒ
const foo = array.toSpliced(1, Infinity);

// โœ…
const foo = array.toSpliced(1);
// โŒ
const foo = array.toSpliced(1, Number.POSITIVE_INFINITY);

// โœ…
const foo = array.toSpliced(1);
// โŒ
array.splice(1, string.length);

// โœ…
array.splice(1);
// โŒ
array.splice(1, Infinity);

// โœ…
array.splice(1);
// โŒ
array.splice(1, Number.POSITIVE_INFINITY);

// โœ…
array.splice(1);