no-param-reassign: function type exceptions
See original GitHub issueWhat 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.
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
- 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:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
reduce
is a function that would be nice to allow modifyingaccumulator
(with the rule on).@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 assignline
to a temporary variable inside your event handler and modify that variable instead?