Disallow using .length
or Infinity
as the deleteCount
or skipCount
argument of Array#{splice,toSpliced}()
💼 This rule is enabled in the ✅ recommended
config.
🔧 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.
// ❌
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);