charCodeAt or String.fromCharCode works on UTF-16 code units, which splits characters outside the basic plane

tx0/ts:code-unit-string-methodstrictwarningreliability/strings-and-regexdepth fastbug

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.

Example from the rule's tests
export const code = (s: string) => s.charCodeAt(0);tx0 reports: this works on UTF-16 code units
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.