unicorn/no-unnecessary-array-splice-count
Disallow .length or Infinity as the count of splice() and toSpliced()
fixable
splice(start) and toSpliced(start) already remove everything from start to the end of the array. Passing the array's .length, Infinity or Number.POSITIVE_INFINITY as the second argument does the same thing with more code.
--fix removes the second argument.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/no-unnecessary-array-splice-count" = "error" # or "warn"Examples#
example.js3 problems
queue.splice(3, queue.lengthPassing queue.length as the deleteCount argument is unnecessary.);
queue.splice(3, InfinityPassing Infinity as the deleteCount argument is unnecessary.);
const firstThree = queue.toSpliced(3, Number.POSITIVE_INFINITYPassing Number.POSITIVE_INFINITY as the deleteCount argument is unnecessary.);example.jsNo problems
queue.splice(3);
const firstThree = queue.toSpliced(3);
// a real count, the length of another array, or items to insert
queue.splice(3, 2);
queue.splice(3, removed.length);
queue.splice(3, queue.length, next);