Skip to content

regexGraphemeStringLiterals

Reports string literals inside character classes with the v flag that contain multiple graphemes.

✅ This rule is included in the ts stylisticStrict presets.

When using the v flag (Unicode sets mode), character classes support string literals using the \q{...} syntax. These string literals are intended to match a single grapheme or character sequence that behaves as a unit. Using multi-grapheme strings inside these literals confuses the distinction between string matching and character class behavior.

If you need to match multi-character strings, use regular alternation with a non-capturing group instead of string literals inside character classes.

const pattern = /[\q{abc}]/v;
const pattern = /[\q{a|bc}]/v;
const pattern = /[\q{hello|world}]/v;

This rule is not configurable.

If you intentionally use multi-grapheme string literals in character classes and understand the semantic difference between string matching and character class behavior, you might prefer to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.