-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [prefer-string-starts-ends-with] Option to ignore [0] === cases? #7140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would avoid against const adlam = "𞤢𞤣𞤤𞤢𞤥"; // All lowercase: "adlam"
console.log(adlam[0]); // '\uD83A'; only a surrogate pair, not a character
console.log(adlam[0] === adlam[0].toUpperCase()); // true??
console.log(/^\P{Lowercase_Letter}/u.test(adlam)); // false; looks better |
TIL Also worth noting that the regex approach is much, much, much slower.
I think that in some codebases you're going to want to be i18n friendly and use the regex approach - but in a lot of cases the index approach is going to be just fine. For example in our codebase I'm fine with us only supporting latin characters because that covers 99.9999% (i'd actually hazard a guess that it's 100% TBH) of usecases and is faster. |
So what's the scope here? Here's my attempt:
Because I assume we still want to report Also for symmetry we probably want to treat the last element the same as well ( |
Breaking it down - we really have a two cases here.
|
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/play/#ts=5.0.4&sourceType=module&code=CYUwxgNghgTiAEYD2A7AzgF3gNyhAriAFzyYwCWKA5gNwBQd5AZvABS4EgDaADALrwAvMJx5CvPgDoMSAKoAHeSBgBhKGhCsAlFvgBvOvHgB6Y-EkW6AXwbM2HQpMywMaAOrkMAC3Zju-aTlFZTUNbR19QxMzC0lrOiA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WluXxUmAc374AhtHzJ6TACYyA7pXwALdFF7QA9tEjgwAXxCGgA
Description
Coming over from #7138 (comment): when checking whether a string's
[0]
member equals a modification of[0]
, the rule's preference ends up being even more code:Agreeing with @bradzacher:
It's not yet clear to me how we would categorize and describe "this case". Maybe it's that we don't want to flag cases that are just checking whether
value[0] ===
something? In that case, maybe the option would be named something likecheckFirstElementEquality
?Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: