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);