Rule suggestion: Avoid modifying object references
See original GitHub issueIn my opinion it is generally dangerous to change the input parameter of a function if it is not a primitive type. It could e.g. result in side effects that are hard to debug because the referenced object is changed in the function.
While I think we won’t be able to detect every possible fault, I suggest creating a rule that at least catches the simple case:
// These cases could be an error or a warning if the rule is enabled
function foo1 (bar) {
bar.thisPropertyAlreadyExisted = somethingElse;
}
function foo2 (bar) {
delete bar.thisPropertyAlreadyExisted;
}
// This is most likely to hard to implement
function foo3 (bar) {
var temp = bar.thisPropertyAlreadyExisted;
temp.deepProperty = somethingElse;
}
What do you think about this?
<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:9 (9 by maintainers)
Top Results From Across the Web
How to prevent modification of objects in Collection without ...
Just make it an "immutable" type: public int Value { get; private set; } (And if the outside code wants to change the...
Read more >OBJ13-J. Ensure that references to mutable objects are not ...
This rule does not address private mutable objects, see rule OBJ05-J. Do not return references to private mutable class members for more information....
Read more >Formula field - limit on a number of object references
THis is a known issue. There is a limit on the number of object references used in validation rules, formula fields , workflows...
Read more >Washing your code: avoid mutation - Artem Sapegin
Mutations happen when we change a JavaScript object or array without ... And one of the most common suggestions I give in code...
Read more >Is it Bad Practice to Modify Instances by Passing Them by ...
generally you should avoid one type mutating another type. its just hard to keep track of what is going on. mutable objects are...
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 Free
Top 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
Is there any way to get the
{ props: true }
behavior without enablingno-param-reassign
?I’d say don’t worry about anything that needs path analysis. Just doing a basic check is good enough to start.