unicorn/prefer-string-slice Pedantic
What it does
Prefer String#slice() over String#substr() and String#substring().
Why is this bad?
String#substr() and String#substring() are the two lesser known legacy ways to slice a string. It's better to use String#slice() as it's a more popular option with clearer behavior that has a consistent Array counterpart.
Examples
Examples of incorrect code for this rule:
javascript
"foo".substr(1, 2);Examples of correct code for this rule:
javascript
"foo".slice(1, 2);How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/prefer-string-slicejson
{
"rules": {
"unicorn/prefer-string-slice": "error"
}
}