Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 999 Bytes

no-unnecessary-slice-end.md

File metadata and controls

36 lines (25 loc) · 999 Bytes

Disallow using .length or Infinity as the end argument of {Array,String,TypedArray}#slice()

💼 This rule is enabled in the ✅ recommended config.

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