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: require-unicode-regexp #9961

Closed
mysticatea opened this issue Feb 9, 2018 · 4 comments · Fixed by #10698
Closed

Rule Proposal: require-unicode-regexp #9961

mysticatea opened this issue Feb 9, 2018 · 4 comments · Fixed by #10698
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 rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

Please describe what the rule should do:

This rule enforces people to use RegExp u flag.

Because of Annex B.1.4 Regular Expressions Patterns, regular expressions have different between u flag or not. For example:

/a{/.test("a{12}")     //→ true
/a{/u.test("a{12}")    //→ Incomplete quantifier
/a{1/.test("a{12}")    //→ true
/a{1/u.test("a{12}")   //→ Incomplete quantifier
/a{12/.test("a{12}")   //→ true
/a{12/u.test("a{12}")  //→ Incomplete quantifier
/a{12}/.test("a{12}")  //→ false
/a{12}/u.test("a{12}") //→ false
/\x/.test("x")         //→ true
/\x/u.test("x")        //→ Invalid escape

This is similar to "use strict".
The u flag makes clearer syntax and helps to catch mistakes early.

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

[X] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

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

//✘ BAD
/foo/

//✓ GOOD
/foo/u

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

We have strict rule for "use strict".
This rule is similar to the strict rule, disabling legacy syntax to catch mistakes early.

@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 Feb 9, 2018
@ljharb
Copy link
Sponsor Contributor

ljharb commented Feb 9, 2018

I like the rule, but I'm not sure the name is appropriate - "strict" is pretty broad.

What about require-unicode-regexp?

@mysticatea
Copy link
Member Author

Sounds good to me.

@mysticatea mysticatea changed the title Rule Proposal: strict-regexp Rule Proposal: require-unicode-regexp Feb 9, 2018
@mysticatea mysticatea self-assigned this Feb 9, 2018
@platinumazure
Copy link
Member

@eslint/eslint-team Can we get one more supporter for this proposal? Otherwise, I think we need to close this.

@aladdin-add aladdin-add added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 21, 2018
@not-an-aardvark
Copy link
Member

This issue is now accepted.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 30, 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 30, 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 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants