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 no-extra-parens #6944

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

Add a --fix option for no-extra-parens #6944

not-an-aardvark opened this issue Aug 20, 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

not-an-aardvark commented Aug 20, 2016

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

I think it would be useful to have an autofix option for the no-extra-parens rule. I think the fixer would be fairly simple; it would just remove the offending parens from the source code.

Presumably, the fixer would follow the same options as the rule itself to determine whether parentheses are gratuitous. For example:

/* eslint no-extra-parens: "error" */

var foo = (bar && baz) || qux;

// gets fixed to:

var foo = bar && baz || qux;
/* eslint no-extra-parens: ["error", "all", { "nestedBinaryExpressions": false }] */

// does not get fixed, because these parens are not errors with nestedBinaryExpressions: false
var foo = (bar && baz) || qux;

One special case for no-extra-parens is when a parenthesized expression is immediately preceded by a keyword:

//  In this case, the fixer should insert a space in addition to removing the parens:
function foo () {
  return(0);
}

// gets fixed to:

function foo () {
  return 0;
}


// However, the fixer probably should not insert a space if a space is already present:
function foo () {
  return (0);
}

// gets fixed to:

function foo () {
  return 0;
}

If this issue gets accepted, I would be happy to send a PR for it.

edit: Added a special case that I noticed

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 20, 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 20, 2016
@platinumazure
Copy link
Member

Sounds reasonable to me. I'll endorse this (:+1:).

@mysticatea
Copy link
Member

👍

1 similar comment
@gyandeeps
Copy link
Member

👍

@ilyavolodin
Copy link
Member

👍 I'll champion this.

@ilyavolodin ilyavolodin 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 Aug 26, 2016
@nzakas nzakas closed this as completed in c210510 Aug 26, 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

6 participants