Proposal: add 'allowOnTop' option to no-param-reassign rule
See original GitHub issueWhen 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:
- Created 8 years ago
- Reactions:2
- Comments:16 (10 by maintainers)
Top 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 >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
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.
@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.