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: function type exceptions

See original GitHub issue

What version of ESLint are you using?

2.11.1

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

default

Please show your full configuration:

I’m generally OK with airbnb-base concerning this rule:

'no-param-reassign': [2, { 'props': true }],

What did you do?..

However, it would be useful to have exceptions for the whole function types. In my code I’ve bumped into these cases in which eslint was too strict as for me.

  1. Proxy traps.

The target argument for many traps is intended to be modified. See as example: Validation

eslint output: error Assignment to property of function parameter 'obj' no-param-reassign

  1. Node.js stream listeners.

Expanded example from Read File Stream Line-by-Line:

const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
  input: fs.createReadStream('sample.txt')
});

let lineNumber = 0;
rl.on('line', line => {
  if (++lineNumber === 1) line = line.replace(bomRegExp, '');

  line = line.trim();

  if (line) {
    // Do something with the line data.
  }
});

eslint output: Assignment to function parameter 'line' no-param-reassign

In such cases creation an intermediate variable could be overcomplication. May be some additions to the rule like proxyTraps: false, eventListeners: false would be helpful.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daczcommented, Jul 20, 2016

reduce is a function that would be nice to allow modifying accumulator (with the rule on).

1reaction
ilyavolodincommented, Jun 8, 2016

@vsemozhetbyt It seems that what you want goes completely against the idea behind no-param-reassign rule. Why do you want to keep it on in the codebase that requires overriding parameters? Also, couldn’t you assign line to a temporary variable inside your event handler and modify that variable instead?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid no-param-reassign when setting a property on a ...
As this article explains, this rule is meant to avoid mutating the arguments object. If you assign to a parameter and then try...
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 >
What the Heck is the deal with no-param-reassign
The first thought when people see the no-param-reassign error is to copy the parameter value into a locally scoped variable. view plaincopy to ......
Read more >
no-param-reassign foreach
Disallow Reassignment of Function Parameters (no-param-reassign) Assignment to variables declared as function parameters can be misleading and lead to confusing ...
Read more >
Airbnb JavaScript Style Guide()
Types ; References; Objects; Arrays; Destructuring; Strings; Functions; Arrow Functions ... 7.12 Never mutate parameters. eslint: no-param-reassign.
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