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

feat: no-control-regex support v flag #17405

Merged
merged 3 commits into from Jul 26, 2023

Conversation

ota-meshi
Copy link
Member

Prerequisites checklist

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

[X] Changes an existing rule (template)

What changes did you make? (Give an overview)

Refs #17223

This PR modifies the no-control-regex rule and adds support for regexp v flag.

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

@ota-meshi ota-meshi requested a review from a team as a code owner July 23, 2023 02:46
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jul 23, 2023
@netlify
Copy link

netlify bot commented Jul 23, 2023

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 89f418f
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/64c0605b7cc456000802451f

@mdjermanovic mdjermanovic mentioned this pull request Jul 23, 2023
19 tasks
@nzakas nzakas added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules contributor pool labels Jul 24, 2023
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Code LGTM. Can we add in some more tests that use regex literals, too?

@ota-meshi
Copy link
Member Author

Thank you for reviewing this PR. I added two testcases. Could you please check again?

@mdjermanovic mdjermanovic added the new syntax This issue is related to new syntax that has reached stage 4 label Jul 25, 2023
Copy link
Member

@nzakas nzakas 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! Would like @mdjermanovic to verify before merging.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Some weird behavior with "uv":

/* eslint no-control-regex: ["error"] */

/\x11/; // error: Unexpected control character(s) in regular expression: \x11.

RegExp("", "uv"); // error: Unexpected control character(s) in regular expression: \x11.

I'm guessing this happens because in this case validatePattern throws before onPatternEnter is called, so moving this._controlChars = []; into collectControlChars might help (though I'm not sure why it wasn't already there, i.e. is there a reason why onPatternEnter was used for this?).

@ota-meshi
Copy link
Member Author

Thank you for finding the bug!

I added this._controlChars = [] to collectControlChars.
However, I left the onPatternEnter. I added a comment as to why. Could you please check that?

        /*
         * `RegExpValidator` may parse the pattern twice in one `validatePattern`.
         * So `this._controlChars` should be cleared here as well.
         *
         * For example, the `/(?<a>\x1f)/` regex will parse the pattern twice.
         * This is based on the content described in Annex B.
         * If the regex contains a `GroupName` and the `u` flag is not used, `ParseText` will be called twice.
         * See https://tc39.es/ecma262/2023/multipage/additional-ecmascript-features-for-web-browsers.html#sec-parsepattern-annexb
         */

@mdjermanovic mdjermanovic changed the title feat: no-control-regex support v flag feat: no-control-regex support v flag Jul 26, 2023
@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jul 26, 2023
@mdjermanovic
Copy link
Member

Thanks for the explanation, very useful! I hadn't thought of that.

Copy link
Member

@mdjermanovic mdjermanovic 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!

@mdjermanovic mdjermanovic merged commit d4f02e4 into eslint:main Jul 26, 2023
22 checks passed
@ota-meshi ota-meshi deleted the no-control-regex branch July 26, 2023 11:57
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jan 23, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jan 23, 2024
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 contributor pool enhancement This change enhances an existing feature of ESLint feature This change adds a new feature to ESLint new syntax This issue is related to new syntax that has reached stage 4 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants