new-parens: add ability to allow chained prop/method access
See original GitHub issueWhat rule do you want to change? new-parens
Does this change cause the rule to produce more or fewer warnings? Fewer
How will the change be implemented? (New option, new default behavior, etc.)? New option
Please provide some example code that this change will affect:
let year = new Date().getFullYear();
What does the rule currently do for this code? Displays an error
What will the rule do after it’s changed?
Allow this code new Date().getFullYear()
and disallow this code new Date()
Are you willing to submit a pull request to implement this change? No
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Use parental controls on your child's iPhone, iPad, and iPod ...
Choose Unrestricted Access, Limit Adult Websites, or Allowed Websites. Depending on the access you allow, you might need to add information, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This makes sense to me. An option to allow only necessary parens (those that wouldn’t require adding outer parens instead), either as an additional modifier for the
"never"
option or maybe as a new value for the string option (something like"as-needed"
).I left 👍 for the proposal. A rule enhancement needs 3 votes from the team and a champion to be accepted.
I’ll champion and I could work on this. Removed my vote to avoid confusion, so this now needs two more 👍 from the team to be accepted.
In favor of the proposal, the same code which would be added for this enhancement can be also used to improve the fixer for the existing behavior. In particular, to avoid unnecessary parens in the autofix when the option is
"never"
. In the actual version, the fixer always wraps thenew
expression in parens.For example,
const foo = new Bar();
becomesconst foo = (new Bar);
like in this demo