charAtComparisons
Reports comparing charAt() results with strings longer than one character.
✅ This rule is included in the ts logical 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.
Examples
Section titled “Examples”text.charAt(0) === "ab";"abc" === text.charAt(0);text.charAt(0) !== "hello";text.charAt(0) === "a";text.slice(0, 2) === "ab";text.startsWith("ab");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule catches a specific programming error with no legitimate use cases. There is no reason to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Oxlint:
oxc/bad-char-at-comparison
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.