charCodeAt or String.fromCharCode works on UTF-16 code units, which splits characters outside the basic plane
What it finds
Characters such as emoji take two UTF-16 code units. charCodeAt returns one half of such a pair and String.fromCharCode builds strings from halves, so text handling with them breaks on those characters. codePointAt and String.fromCodePoint work on whole characters.
Reported are calls of charCodeAt and of String.fromCharCode.
From the rule's source, code_unit_string_method.rs.
export const code = (s: string) => s.charCodeAt(0);tx0 reports: this works on UTF-16 code units Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:code-unit-string-method" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:code-unit-string-method] reason="..."tx0 explain tx0/ts:code-unit-string-method shows the same in the terminal. Found a false positive? Report it.