Skip to content
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

Rule Proposal: no-multi-code-point-character-in-character-class #10049

Closed
mysticatea opened this issue Mar 3, 2018 · 3 comments · Fixed by #10511
Closed

Rule Proposal: no-multi-code-point-character-in-character-class #10049

mysticatea opened this issue Mar 3, 2018 · 3 comments · Fixed by #10511
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint needs bikeshedding Minor details about this change need to be discussed rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

Please describe what the rule should do:

If RegExp character class has multi-code-point character, it causes unexpected behavior, even if you are using u flag.

/^[❇️]$/u.test("❇️") //→ false

In above example, the ❇️ is made with two code points U+2747 and U+FE0F. JavaScript doesn't handle it as a character, so the character class matches to U+2747 or U+FE0F rather than the character. The U+FE00-FE0F is Variation Selectors.

Another well-known case is ZWJ U+200D. ZWJ joins multiple code points to a character.

/^[👨‍👩‍👦]$/u.test("👨‍👩‍👦") //→ false

So, this rule prevents characters which are made with multiple code points in character class syntax.

What category of rule is this? (place an "X" next to just one item)

[X] Warns about a potential error

Provide 2-3 code examples that this rule will warn about:

/[👍]/ // ERROR: a surrogate pair in a character class without u flag.
/[❇️]/u // ERROR: variation selectors in a character class.
/[👨‍👩‍👦]/u // ERROR: ZWJ in a character class.
/[🇯🇵]/u // ERROR: a U+1F1E6-1F1FF pair in a character class.
/[👶🏻]/u // ERROR: an emoji which is made with an emoji and skin tone selector, in a character class.

Why should this rule be included in ESLint (instead of a plugin)?

This is not library specific matter and it's difficult to distinguish whether character class syntax handles the character as one character or not.

@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Mar 3, 2018
@mysticatea mysticatea self-assigned this Mar 3, 2018
@not-an-aardvark
Copy link
Member

👍, but I feel like the rule name is a bit too long. How about something like no-invalid-character-classes or no-surrogate-pair-character-classes?

@mysticatea
Copy link
Member Author

I agree. In fact, my first idea was no-destructuring-character-classes, but the word is used in destructuring assignment syntax.

no-invalid-character-classes is not bad.
no-surrogate-pair-character-classes sounds misleading since u flag can handle surrogate pairs correctly.

Hmm, how about no-dismantling-character-classes? The purpose of the rule is to report character classes which dismantle one character to multiple characters.

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion needs bikeshedding Minor details about this change need to be discussed and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jun 12, 2018
@platinumazure
Copy link
Member

Marking as accepted.

I've also added "needs bikeshedding" since we need to agree on a name.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 27, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jan 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint needs bikeshedding Minor details about this change need to be discussed rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants