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

New: require-unicode-regexp rule (fixes #9961) #10698

Merged
merged 5 commits into from
Aug 2, 2018
Merged

New: require-unicode-regexp rule (fixes #9961) #10698

merged 5 commits into from
Aug 2, 2018

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] New rule: fixes #9961.

What changes did you make? (Give an overview)

This PR adds require-unicode-regex rule.

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@mysticatea mysticatea added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint labels Jul 29, 2018
Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor comments, but this is looking great!

url: "https://eslint.org/docs/rules/require-unicode-regexp"
},
messages: {
requireUFlag: "Require 'u' flag."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be phrased better:

  • "'u' flag is required."
  • Use the 'u' flag."

errors: [{ messageId: "requireUFlag" }]
},
{
code: "const flags = 'gimu'; new RegExp('foo', flags.slice(0, -1))",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. The documentation says this test should be valid (i.e., rule ignores these cases where flags is non-constant variable), but this test is in the invalid section. Seems either this or the documentation needs to change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My word choice seemed bad. That ignores a RegExp call if it couldn't evaluate the 2nd argument to a static value in the file. In the test case, flags.slice(0, -1) is evaluated to 'gim' under the assumption that the standard APIs are valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I assumed this wouldn't be determined statically, but I spent a few minutes looking at your eslint-utils module, specifically the getStaticValue implementation, and I am thoroughly impressed with how powerful it is 👏

@mysticatea
Copy link
Member Author

I updated the error message and the documentation.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nits, but the implementation and tests look great! Neither nit is worthy of preventing merging if you don't get to them. I'm impressed with how thorough the static analysis is in the constructor/call case!

@@ -0,0 +1,55 @@
# enforce the use of `u` flag on RegExp (require-unicode-regexp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: can you capitalize the first letter of "Enforce"?

@@ -0,0 +1,65 @@
/**
* @fileoverview Rule to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @fileoverview description is incomplete

const c = new RegExp("ccc", "u")
const d = new RegExp("ddd", "giu")

// This rule ignores RegExp calls if the flags could not be evaluated to a static value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to clarify this 👏

errors: [{ messageId: "requireUFlag" }]
},
{
code: "const flags = 'gimu'; new RegExp('foo', flags.slice(0, -1))",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I assumed this wouldn't be determined statically, but I spent a few minutes looking at your eslint-utils module, specifically the getStaticValue implementation, and I am thoroughly impressed with how powerful it is 👏

@mysticatea mysticatea merged commit 6eb972c into master Aug 2, 2018
@mysticatea mysticatea deleted the issue9961 branch August 2, 2018 06:00
@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 this pull request may close these issues.

Rule Proposal: require-unicode-regexp
3 participants