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.

Proposal: add 'allowOnTop' option to no-param-reassign rule

See original GitHub issue

When allowOnTop is true, reassign is allowed at the beginning of function scope (same concept like var statement in vars-on-top rule).

The reason - I don’t want to reassign params except intended setting default like:

function (data) {  
   data = data || 0;
   ...
}

This can be avoided in ES6 with default arguments, but they can’t used in all cases, for instance making a defensive copy:

function (data) {  
   data = _.clone(data);
   ...
}

You can use _ prefix or new variable dataCopy but i don’t like it much. In fact I want to hide original variable to prevent unwanted access to unsafe origin.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Dec 21, 2016

For future explorers: v8 severely deoptimizes a function in sloppy mode when you assign arguments, even on top, so it’s potentially a big performance hazard - not “just” style.

0reactions
ljharbcommented, Jul 9, 2017

@cipri-tom reassignment doesn’t have side effects; primitives are immutable (so “changing them” doesn’t apply). Reassignment isn’t bad because it has side effects; it’s bad because you should just make a new variable, for clarity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-param-reassign - ESLint - Pluggable JavaScript Linter
This rule takes one option, an object, with a boolean property "props" , and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex" .
Read more >
How to avoid no-param-reassign when setting a property on a ...
Modifying a property of an object that was passed as a parameter doesn't change the object reference, so it shouldn't run into the...
Read more >
Rule no-param-reassign - ESLint中文
This rule aims to prevent unintended behavior caused by overwriting function parameters. Options. This rule takes one option, an object, with a property...
Read more >
Update eslintrc no-param-reassign to allow props reassignment
Update .eslintrc.yml to allow prop reassignment for the rule no-param-reassign; Removes unused eslint-disable that this change caused.
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