[no-extra-parens] Allow an exception for (new X()).y
See original GitHub issueWhat 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 https://github.com/eslint/eslint/pull/12302.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:8 (7 by maintainers)
I’m willing to champion and work on this.
Just to confirm the details of this enhancement, if I understand correctly the following should be done.
The option applies only to the change made in v6.5.0 (part of #12302):
Other cases of unnecessary parens around
new X()
that were warnings in previous versions will remain warnings, regardless of how the option is set. For example:The name of the option could be
enforceForNewInMemberExpressions
?Since it’s default behavior in the actual version, the default value is
true
:When the option is explicitly set to
false
,(new X()).y
and(new X())[y]
are allowed: