Rule suggestion: Don't reassign function parameters
See original GitHub issueReusing function parameters feels often like a code smell for me. If you consider something like the following example it could even cost you some debugging time (especially if you have long legacy functions):
function foo (bar) {
bar = 13;
// now we accidentally overwrote the function parameter which is most likely not good
}
I suggest the implementation of a rule that is similar to no-ex-assign but for functions instead of try-catch-blocks and is turned off by default.
What do you think about it?
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 9 years ago
- Comments:28 (21 by maintainers)
Top Results From Across the Web
How to avoid no-param-reassign when setting a property on a ...
If you assign to a parameter and then try and access some of the parameters via the arguments object, it can lead to...
Read more >no-param-reassign - ESLint - Pluggable JavaScript Linter
Rule Details This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.
Read more >Why it's bad practice to reassign function params - Medium
Reassigning the value of an argument variable mutates the arguments object. Mutation is the act of changing the source or the original element....
Read more >Effective Go - The Go Programming Language
The return or result "parameters" of a Go function can be given names and used as regular variables, just like the incoming parameters....
Read more >Google C++ Style Guide
Comment Style; File Comments; Class Comments; Function Comments ... This principle mostly explains the rules we don't have, rather than the rules we...
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
@xjamundx oh, I see. I did not know about () around {} when returning object in short function.
That’s actually just flowtype, not typescript.
@idchlife this is valid ES6
[1,2].map(c => ({a: 1}))
not sure about TypeScript?