update documentation re no-param-reassign
See original GitHub issueGreat tool. I hope this idea might help.
no-param-reassign
is a solid rule for good reason (it’s not intuitive that a function’s arguments is recorded as an array, not a key-value).
However, may I suggest the one time the user can safely ignore this rule: creating an object from an array using reduce. I use the eslint-rules for three reasons (loosely speaking):
- safety that includes consistent, clean design
- idiomatic to plug-into norms and thus increase speed of understanding
- performance without sacrificing on safety
My recommendation would be to describe how avoiding a destructuring call on every iteration of the reducing function likely provides a net benefit when building an object from an array using reduce.
This is such an often used function (reduce
), that I believe it merits this special “calling out”.
What do you all think?
- E
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
no-param-reassign - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >How to avoid no-param-reassign when setting a property on a ...
This answer should be the accepted answer since it's pointing to the official documentation and is well explained. Most of the other answers...
Read more >Do we want to recommend the `no-param-reassign` eslint rule ...
I just had this idea when another user tried to assign to the state function argument. There is actually an eslint rule for...
Read more >What the Heck is the deal with no-param-reassign
When a variable holds a primitive (Number or String) and you re-assign its value your pointing it to a new memory location. view...
Read more >Update eslintrc no-param-reassign to allow props reassignment
I updated the .eslintry.yml with a draft ignorePropertyModificationsFor list. I think there are some good reasons to include entries for the ...
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
It’s also worthwhile to note that this is a pretty good use case for inline disable comments. You could use those comments in the cases where
acc
is a real accumulator in areduce
function, but not allow mutations ofacc
parameters in other contexts.That said, I wouldn’t oppose improving the docs with a
reduce
example.Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.