Skip to content

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 ​

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

Pass ​

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

Released under the Apache License 2.0.