Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 875 Bytes

no-length-as-slice-end.md

File metadata and controls

30 lines (20 loc) · 875 Bytes

Disallow using .length 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 is unnecessary.

Fail

const foo = string.slice(1, string.length);
const foo = array.slice(1, array.length);

Pass

const foo = string.slice(1);
const foo = bar.slice(1, baz.length);