no-unnecessary-slice-end
March 27, 2026 ยท View on GitHub
๐ Disallow using .length or Infinity as the end argument of {Array,String,TypedArray}#slice().
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
When calling {String,Array,TypedArray}#slice(start, end), omitting the end argument defaults it to the object's .length. Passing it explicitly or using Infinity is unnecessary.
Examples
// โ
const foo = string.slice(1, string.length);
// โ
const foo = string.slice(1);
// โ
const foo = string.slice(1, Infinity);
// โ
const foo = string.slice(1);
// โ
const foo = string.slice(1, Number.POSITIVE_INFINITY);
// โ
const foo = string.slice(1);