Skip to content

Latest commit

Β 

History

History
64 lines (45 loc) Β· 1.61 KB

File metadata and controls

64 lines (45 loc) Β· 1.61 KB

no-unnecessary-array-splice-count

πŸ“ 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);