prefer-string-starts-ends-with
Configuration
rslint.config.ts
Rule Details
Enforce using String#startsWith and String#endsWith over other equivalent methods of checking substrings.
There are multiple ways to verify if a string starts or ends with a specific string, such as foo.indexOf('bar') === 0, foo.charAt(0) === 'b', or regex tests like /^bar/.test(foo). Since ES2015 has added String#startsWith and String#endsWith, this rule reports on other ways of checking, suggesting the use of the built-in methods instead.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowSingleElementEquality
When set to "always", allows equality checks for a single character (e.g. foo[0] === 'a' and foo.charAt(0) === 'a').