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
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
There was a problem hiding this 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?
Thank you for reviewing this PR. I added two testcases. Could you please check again? |
There was a problem hiding this 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.
There was a problem hiding this 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?).
Thank you for finding the bug! I added /*
* `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
*/ |
no-control-regex
support v flagno-control-regex
support v
flag
Thanks for the explanation, very useful! I hadn't thought of that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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 regexpv
flag.Is there anything you'd like reviewers to focus on?