Skip to content

Rule Change: Suggestions for prefer-regex-literals disallowRedundantWrapping option #16516

@yeonjuan

Description

@yeonjuan

What rule do you want to change?

prefer-regex-literals

What change to do you want to make?

Implement suggestions

How do you think the change should be implemented?

Other

Example code

/* eslint prefer-regex-literals: ["error", {"disallowRedundantWrapping": true}] */
const reg0 = new RegExp('a'); 
const reg1 = new RegExp(/a/);   // no suggestion
const reg2 = new RegExp(/a/, 'g'); // no suggestion

What does the rule currently do for this code?

The rule didn't suggest for unnecessarily wrapped patterns which disallowed by "disallowRedundantWrapping": true. demo

What will the rule do after it's changed?

It will make suggestions for the patterns also.

/* eslint prefer-regex-literals: ["error", {"disallowRedundantWrapping": true}] */
const reg1 = new RegExp(/a/);   //  =>  /a/
const reg2 = new RegExp(/a/, 'g'); // => /a/g
const reg3 = new RegExp(/a/g, 'i') // => /a/i

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions