Skip to content

New: Add prefer-regex-literals rule (fixes #12238)#12254

Merged
ilyavolodin merged 5 commits intomasterfrom
prefer-regex-literals
Sep 14, 2019
Merged

New: Add prefer-regex-literals rule (fixes #12238)#12254
ilyavolodin merged 5 commits intomasterfrom
prefer-regex-literals

Conversation

@mdjermanovic
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread docs/rules/prefer-regex-literals.md Outdated
Comment thread docs/rules/prefer-regex-literals.md Outdated
Comment thread lib/rules/prefer-regex-literals.js Outdated
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
Copy Markdown
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 dismissed platinumazure’s stale review September 14, 2019 00:29

Requests were addressed

@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.

4 participants