regexUnicodeProperties
Reports inconsistent Unicode property names in regular expressions.
✅ This rule is included in the ts stylistic presets.
Unicode properties may be expressed in several different ways. Including the fully-written out category prefix is a more verbose way that is not necessary.
This rule detects inconsistent Unicode property names in regular expressions and suggests more idiomatic forms for:
- Unnecessary
gc=/General_Category=prefix: unicode general category properties can be used without the prefix. - Long script names: short script aliases like
Grekshould use the full nameGreekfor readability.
Examples
Section titled “Examples”Unnecessary General_Category Prefix
Section titled “Unnecessary General_Category Prefix”const pattern = /\p{gc=L}/u;const pattern2 = /\p{General_Category=Letter}/u;const pattern = /\p{L}/u;const pattern2 = /\p{Letter}/u;Short Script Names
Section titled “Short Script Names”const pattern = /\p{sc=Grek}/u;const pattern2 = /\p{Script=Latn}/u;const pattern = /\p{sc=Greek}/u;const pattern2 = /\p{Script=Latin}/u;Script_Extensions
Section titled “Script_Extensions”const pattern = /\p{scx=Cyrl}/u;const pattern = /\p{scx=Cyrillic}/u;RegExp Constructor
Section titled “RegExp Constructor”const pattern = new RegExp("\\p{gc=L}", "u");const pattern2 = new RegExp("\\p{sc=Grek}", "u");const pattern = new RegExp("\\p{L}", "u");const pattern2 = new RegExp("\\p{sc=Greek}", "u");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your project has a style guide that prefers explicit gc= prefixes or short script names for consistency with other documentation, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/unicode-property
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.