Skip to content

no-misleading-character-class

Reports a character class in the constant string given to new Regex(...) and the static methods of Regex, in which a combining mark follows another character.

A combining mark is a separate code point that attaches to the character before it. In a character class each code point is its own member, so the class matches the base letter or the mark alone and never the combined character the author sees.

To fix, write the combined character as a group outside the class, or as a single precomposed character.

Reported
...
void f(String s) {
...
Pattern.matches("[a" + "\u0301]", s);
Pattern.compile("a b");
Other.compile("a b");
Pattern.compile(s);
...
csharp:
lint:
rules:
no-misleading-character-class: warn # off (default), warn, error
java:
lint:
rules:
no-misleading-character-class: warn # off (default), warn, error
js:
lint:
rules:
no-misleading-character-class: warn # off (default), warn, error
php:
lint:
rules:
no-misleading-character-class: warn # off (default), warn, error
python:
lint:
rules:
no-misleading-character-class: warn # off (default), warn, error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-misleading-character-class in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint no-misleading-character-class partial the surrogate pair, emoji modifier, flag and joined-sequence checks are not made