Fix: use regexpp's default ecmaVersion in no-invalid-regexp #13968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Tell us about your environment
What parser (default,
@babel/eslint-parser
,@typescript-eslint/parser
, etc.) are you using?default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
Online Demo
What did you expect to happen?
No errors. These are valid regular expressions per the ES2020 spec, ref tc39/ecma262#1869 (comment) and tc39/ecma262#1468.
Espree with
ecmaVersion: 2020
doesn't report parsing errors in the equivalent regex literals.What actually happened? Please include the actual, raw output from ESLint.
All four
RegExp
calls are reported:What changes did you make? (Give an overview)
In the
no-invalid-regexp
rule I removed the hard-codedecmaVersion: 2018
passed intoRegExpValidator
so that the default regexpp'secmaVersion
is used, like in other rules that use regexpp. I think it's always the latest official version (not counting the draft?). In #10062 it was decided to use the latest version in this rule.This currently bumps
ecmaVersion
from 2018 to 2020 inno-invalid-regexp
.Is there anything you'd like reviewers to focus on?
regexpp
doesn't support 2021, so it wouldn't make a difference at the moment.valid
tests are misleading because this rule doesn't useecmaVersion
from the configuration. Most of theallowConstructorFlags
tests are thus useless. I'll submit a PR to modify the tests."g"
flag in the examples and the tests doesn't have a particular meaning, but I had to add some flags because the logic on when should the rule try to validate the regex both with and without the"u"
flag is currently wrong. For example,new RegExp("\\u{0}*");
is a false negative (it's valid with the"u"
flag, but that flag certainly isn't there in this case). I'll submit a PR to fix that.