Closed
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
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:
declare const value: string;
if (value[0] === value[0].toUpperCase()) { /* ... */ } // before
if (value.startsWith(value[0].toUpperCase())) { /* ... */ } // after
Agreeing with @bradzacher:
I actually think that the previous form is clearer for this specific case.
It's also substantially faster (not that it matters at the this speed... but it is twice as fast - ~1.2B ops/s vs ~2.4B ops/s).I wonder if we should add an option to skip this case from the rule?
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 like checkFirstElementEquality
?
Fail
n/a
Pass
n/a
Additional Info
No response