A character class contains a character made of several code units or code points, which it splits into separate members

tx0/ts:multi-code-point-in-classdefaultwarningreliability/logicdepth fastbug

What it finds

A character class matches one character. Without the u flag, an emoji or other character outside the basic plane is two code units, and with or without it, a letter with a combining mark or an emoji with a modifier is several code points. The class then matches each part on its own, such as half of a surrogate pair.

Reported are literal patterns with a character outside the basic plane in a class and no u or v flag, and classes with a combining mark, variation selector or zero width joiner after another character.

A class of marks on their own, as the range [\u0300-\u036f] that removes accents after normalize("NFD"), splits nothing. Written as raw characters, though, the marks are invisible or attach to the bracket or dash before them. Such a class is reported too, with a safe fix that writes the marks as \u escapes.

From the rule's source, multi_code_point_in_class.rs.

Example from the rule's tests
export const smile = /[๐Ÿ˜€]/;tx0 reports: without the u flag, this class splits a characterexport const fine = /[๐Ÿ˜€]/u;export const thumbs = /[๐Ÿ‘๐Ÿป]/u;tx0 reports: this class splits a character made of several code pointsexport const marks = /[ฬ€-อฏ]/g;tx0 reports: this class lists combining marks as raw characters, which are invisible in the sourceexport const notMarks = /[^ฬ€-อฏ]/;tx0 reports: combining marks as raw charactersexport const tone = /[๐Ÿป-๐Ÿฟ]/;tx0 reports: without the u flag, this class splits a characterexport const escaped = /[\u0300-\u036f]/g;
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:multi-code-point-in-class" = "off"

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:multi-code-point-in-class] reason="..."

tx0 explain tx0/ts:multi-code-point-in-class shows the same in the terminal. Found a false positive? Report it.