regexUnicodeCodepointEscapes
Reports surrogate pair escapes in regular expressions that can be replaced with Unicode codepoint escapes.
✅ This rule is included in the ts stylistic presets.
Reports surrogate pair escapes in regular expressions that can be replaced with Unicode codepoint escapes.
When the u or v flag is present, surrogate pairs like \uD83D\uDE00 can be written as \u{1F600}.
Unicode codepoint escapes are clearer and more maintainable.
Examples
Section titled “Examples”Surrogate Pair in Regex Literal
Section titled “Surrogate Pair in Regex Literal”const emoji = /\uD83D\uDE00/u;const emoji = /\u{1F600}/u;Surrogate Pair in Character Class
Section titled “Surrogate Pair in Character Class”const emoji = /[\uD83D\uDE00]/u;const emoji = /[\u{1F600}]/u;Surrogate Pair with v Flag
Section titled “Surrogate Pair with v Flag”const emoji = /\uD83D\uDE00/v;const emoji = /\u{1F600}/v;Surrogate Pair in RegExp Constructor
Section titled “Surrogate Pair in RegExp Constructor”const emoji = new RegExp("\\uD83D\\uDE00", "u");const emoji = new RegExp("\\u{1F600}", "u");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to support environments that do not support Unicode codepoint escapes, or if you prefer surrogate pairs for consistency with existing code, you might need to disable this rule.
Without the u or v flag, surrogate pairs are required for astral characters.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.