Skip to content

charAtComparisons

Reports comparing charAt() results with strings longer than one character.

✅ This rule is included in the ts logical and logicalStrict presets.

The charAt method returns a string of exactly one character. If the return value is compared with a string of length greater than one, the comparison will always evaluate to the same result. Equality comparisons (===, ==) will always be false, and inequality comparisons (!==, !=) will always be true.

53teAB0char5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53<) sp ansty="le--0:#C792EA;--1:#8844">AE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><";d>1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Da1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE=<==sp ansty="le--0:#D6DEEB;--1:#403F">53 teAB0char5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>53teAB0char5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53<) sp ansty="le--0:#C792EA;--1:#8844">AE!<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dhel1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><";d>
3F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ch30<9820 spans="tyle--0:#D6DEEB;--1:#40">3F<53) spans="tyle--0:#C792EA;--1:#88">44A31<111" spans="tyle--0:#ECC48D;--1:#98">41<111" spans="tyle--0:#D6DEEB;--1:#40">3<"a"><;di vdivclass="Nameexpressive-">3F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0s30<9820 spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">0<9822 spans="tyle--0:#D6DEEB;--1:#40">3F<53) spans="tyle--0:#C792EA;--1:#88">44A31<111" spans="tyle--0:#ECC48D;--1:#98">4E<4Dab spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">3F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0starts31<111" spans="tyle--0:#ECC48D;--1:#98">4E<4Dab spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">

This rule is not configurable.

This rule catches a specific programming error with no legitimate use cases. There is no reason to disable this rule.