question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule suggestion: Avoid modifying object references

See original GitHub issue

In 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:closed
  • Created 9 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ferosscommented, Jul 28, 2015

Is there any way to get the { props: true } behavior without enabling no-param-reassign?

0reactions
nzakascommented, Jul 19, 2015

I’d say don’t worry about anything that needs path analysis. Just doing a basic check is good enough to start.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found