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

Add a --fix option for wrap-regex #7013

Closed
not-an-aardvark opened this issue Aug 29, 2016 · 4 comments
Closed

Add a --fix option for wrap-regex #7013

not-an-aardvark opened this issue Aug 29, 2016 · 4 comments
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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@not-an-aardvark
Copy link
Member

I'm using Node v6.4.0 and ESLint v3.4.0.

It would be useful to have an autofix option for the wrap-regex rule. The fixer would simply wrap all regular expression literals with parentheses, if they aren't parenthesized already.

var hasFoo = /foo/.test(myStr);

// gets fixed to:

var hasFoo = (/foo/).test(myStr);

We would need to ensure that adding parentheses doesn't cause the regex to be interpreted as a function parameter (like with no-unexpected-multiline). However, I don't think this is an issue, because in scenarios like this, the regex is parsed as a division operator anyway:

var unrelated = 'foo' // <-- no semicolon
/regex/.test('bar');

// This is a SyntaxError even before parentheses are added,
// because `/` is parsed as a division operator.

I would be willing to add this if the issue is accepted.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 29, 2016
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Aug 29, 2016
@platinumazure
Copy link
Member

Seems reasonable to me. 👍

@mysticatea
Copy link
Member

👍

1 similar comment
@ilyavolodin
Copy link
Member

👍

@mysticatea
Copy link
Member

I will go to a champion.
Then, there are 3 👍s from the team.

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 4, 2016
@btmills btmills closed this as completed in e118728 Sep 6, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

5 participants