Skip to content

unicorn/no-length-as-slice-end Restriction

🛠️ An auto-fix is available for this rule.

What it does

Disallow using length as the end argument of a slice call.

Why is this bad?

Passing length as the end argument of a slice call is unnecessary and can be confusing.

Example

Examples of incorrect code for this rule:

javascript
foo.slice(1, foo.length);

Examples of correct code for this rule:

javascript
foo.slice(1);

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/no-length-as-slice-end
json
{
  "rules": {
    "unicorn/no-length-as-slice-end": "error"
  }
}

References

Released under the MIT License.