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: Add prefer-regex-literals rule (fixes #12238) #12254

Merged
merged 5 commits into from Sep 14, 2019

Conversation

mdjermanovic
Copy link
Member

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

[X] New rule #12238

Examples of incorrect code for this rule:

new RegExp("abc");
new RegExp("abc", "u");
RegExp("abc");
RegExp("abc", "u");
new RegExp("\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d");
RegExp(`^\\d\\.$`);
new RegExp(String.raw`^\d\.$`);

Examples of correct code for this rule:

/abc/;
/abc/u;
/\d\d\.\d\d\.\d\d\d\d/;
/^\d\.$/;
// RegExp constructor is allowed for dynamically generated regular expressions
new RegExp(pattern);
RegExp("abc", flags);
new RegExp(prefix + "abc");
RegExp(`${prefix}abc`);
new RegExp(String.raw`^\d\. ${sufix}`);

What changes did you make? (Give an overview)

Added new rule prefer-regex-literals

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

@mdjermanovic mdjermanovic 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 Sep 10, 2019
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.

Some minor documentation tweaks and one question.

Also, I wanted to note that you can pass parserOptions to the RuleTester constructor, and have them be the default on all tests. I don't personally think there is much value in having the parserOptions set for each test since, if the user tried to use template literals without the right ecmaVersion, the rule wouldn't even run. So, if you want to save some lines, you could pass parserOptions: { ecmaVersion: 2015 } to the RuleTester constructor. But I don't feel strongly about this at all.

docs/rules/prefer-regex-literals.md Outdated Show resolved Hide resolved
docs/rules/prefer-regex-literals.md Outdated Show resolved Hide resolved
lib/rules/prefer-regex-literals.js Outdated Show resolved Hide resolved
mdjermanovic and others added 4 commits September 11, 2019 00:08
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
Co-Authored-By: Kevin Partington <platinum.azure@kernelpanicstudios.com>
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@ilyavolodin ilyavolodin merged commit 3be04fd into master Sep 14, 2019
@ilyavolodin ilyavolodin deleted the prefer-regex-literals branch September 14, 2019 00:29
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 13, 2020
@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 Mar 13, 2020
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.

None yet

4 participants