Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
{"rules": {"@typescript-eslint/prefer-string-starts-ends-with": ["error"] }}
exportfunctionisThreeCharPrefixMatch(str:string,candidate:string):boolean{returnstr.substring(0,3)===candidate;}
tsconfig
: the default as generated bytsc --init
Expected Result
No error, since asubstring
call other thansubstring(0)
can not be replaced withstartsWith
alone.
Actual Result
The following error was printed:
2:10 error Use 'String#startsWith' method instead @typescript-eslint/prefer-string-starts-ends-with
Additional Info
Consider the code with the change suggested by the linter:
exportfunctionisThreeCharPrefixMatchB(str:string,candidate:string):boolean{returnstr.startsWith(candidate);}
Now
> isThreeCharPrefixMatch("int32", "in");false> isThreeCharPrefixMatchB("int32", "in");true
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 5.4.0 |
@typescript-eslint/parser | 5.4.0 |
TypeScript | 4.5.2 |
ESLint | 8.2.0 |
node | 12.22.5 |