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);