Skip to content

[no-extra-parens] Allow an exception for (new X()).y #12428

@domenic

Description

@domenic

What rule do you want to change? no-extra-parens

Does this change cause the rule to produce more or fewer warnings? Fewer, if configured

How will the change be implemented? (New option, new default behavior, etc.)? New option, similar to the existing ones like returnAssign, nestedBinaryExpressions, etc.

Please provide some example code that this change will affect:

const doc = (new JSDOM()).window.document;

const { document } = (new JSDOM(`<!doctype html><html><head></head><body>
  <div></div><div title=""></div><div title="yes"></div>
</body></html>`)).window;

What does the rule currently do for this code?

It requires removing the parens, i.e. that I write

const doc = new JSDOM().window.document;

const { document } = new JSDOM(`<!doctype html><html><head></head><body>
  <div></div><div title=""></div><div title="yes"></div>
</body></html>`).window;

This is equivalent, but it feels really weird. Although the new operator binds more closely than the . operator in JS, this is a somewhat-surprising feature of JS, as . otherwise binds very high, and most space-separated operators bind quite low.

What will the rule do after it's changed?

Allow the above code, when a new option is configured, e.g."newExpressions": false.

Are you willing to submit a pull request to implement this change?

Yes, although a community volunteer would be much appreciated.

Other note

This changed in v6.5.0 as part of #12302.

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

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions