unicorn/prefer-string-starts-ends-with Correctness
What it does
Prefer String#startsWith() and String#endsWith() over using a regex with /^foo/ or /foo$/.
Why is this bad?
Using String#startsWith() and String#endsWith() is more readable and performant as it does not need to parse a regex.
Examples
Examples of incorrect code for this rule:
javascript
const foo = "hello";
/^abc/.test(foo);Examples of correct code for this rule:
javascript
const foo = "hello";
foo.startsWith("abc");How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/prefer-string-starts-ends-withjson
{
"rules": {
"unicorn/prefer-string-starts-ends-with": "error"
}
}