Skip to content

Force one grapheme in the disjunction of string literals #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ota-meshi opened this issue Oct 4, 2023 · 0 comments · Fixed by #646
Closed

Force one grapheme in the disjunction of string literals #644

ota-meshi opened this issue Oct 4, 2023 · 0 comments · Fixed by #646
Labels
enhancement New feature or request new rule

Comments

@ota-meshi
Copy link
Owner

Motivation

It may be useful to be able to force the disjunction of string literals to use only strings that humans recognize as single characters.

Description

It is possible to use strings of two or more characters in the disjunction of string literals, but normal disjunction is also possible. (However, there are differences in the evaluation order.)
Forcing a single character to be used in the disjunction of string literals allows people to distinguish between uses.

I think it is better to implement the rule by using Intl.Segmenter and allowing it if it is recognized as one grapheme.

Examples

/* ✓ GOOD */
var foo = /[\p{RGI_Emoji}--\q{🇦🇨|🇦🇩|🇦🇪|🇦🇫|🇦🇬|🇦🇮|🇦🇱|🇦🇲|🇦🇴|🇦🇶|🇦🇷|🇦🇸|🇦🇹|🇦🇺|🇦🇼|🇦🇽|🇦🇿|🇧🇦|🇧🇧|🇧🇩|🇧🇪|🇧🇫|🇧🇬|🇧🇭|🇧🇮|🇧🇯}]/v

/* ✗ BAD */
var foo = /[\q{abc|def}]/v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant