unicorn/no-unnecessary-slice-end
Disallow .length or Infinity as the end of slice()
fixable
slice(start) already goes to the end of the array or string. Passing the value'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-slice-end" = "error" # or "warn"Examples#
example.js3 problems
const rest = items.slice(1, items.lengthPassing items.length as the end argument is unnecessary.);
const extension = filename.slice(dot, InfinityPassing Infinity as the end argument is unnecessary.);
const tail = lines.slice(-5, Number.POSITIVE_INFINITYPassing Number.POSITIVE_INFINITY as the end argument is unnecessary.);example.jsNo problems
const rest = items.slice(1);
const extension = filename.slice(dot);
const tail = lines.slice(-5);
// a real end, or the length of something else
const page = items.slice(0, 10);
const prefix = filename.slice(0, base.length);