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.

no-param-reassign should not throw error when using Object destructuring on parameters

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.9.0
  • Node Version: v8.11.3
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
{
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "rules": {
    "no-param-reassign": [
      "error",
      {
        "props": true
      }
    ]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

const obj = { key: [1, 2, 3] };

function foo({ key }) {
  key = [4, 5, 6];
  return key;
}

function bar(qux) {
  let { key } = qux;
  key = [4, 5, 6];
  return key;
}
node_modules/eslint/bin/eslint.js demo.js

What did you expect to happen? 0 error

What actually happened? Please include the actual, raw output from ESLint. 4:3 error Assignment to function parameter 'key' no-param-reassign

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Apr 14, 2019

@pantoninho Possible misreading on my part:

I might be wrong but when we use object destructuring on the arguments, we are creating mutable local variables that point to the value of the object property of the same name.

Guess I took that out of context and read that as an assertion about the leakage of assignments to an object property “through” an assignment to a destructured value. My mistake.

In any case, I still recommend creating a new issue, so that you can provide full context for your use case.

0reactions
pantoninhocommented, Apr 14, 2019

@platinumazure I can understand why it was easy to misread, sorry.

I will follow your advice. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolving ESLint error due to `no-param-reassign` and `prefer ...
The first error is here because in your eslint configuration you use the following: no-param-reassign: ["error", { "props": true }].
Read more >
Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty {} to prevent it from throwing an error! function hi(person)...
Read more >
no-param-reassign - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
Here we show how to unpack a property of the passed object into a variable with the same name. The parameter value {...
Read more >
eslint-config-airbnb - Awesome JS
2.2 If you must reassign references, use let instead of var . eslint: no-var ... 5.3 Use object destructuring for multiple return values,...
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