-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Because of our no-param-reassign
rule, a lot of redeclaration of a function parameter is done, e.g. in parser.js:
_preprocess(node, context, config) {
const element = node; //redecl
const self = this;
...
}
Why this rule is recommended is because reassigning the function parameter can cause the arguments
object to be weird:
var makePerson = function(favoriteColor, name, age) {
if (arguments.length < 3) {
favoriteColor = "green";
name = arguments[0];
age = arguments[1];
}
return {
name: name,
age: age,
favoriteColor: favoriteColor
};
};
var person = makePerson("Joe", 18);
console.log(JSON.stringify(person));
// => {"name":"green","age":"green","favoriteColor":"green"}
https://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/
This won't happen if we are just changing properties on the parameter!
(Describe your proposed solution here.)
Let's override the eslint rule with "no-param-reassign": ["error", { "props": false }]
, so that we can change properties on parameters, and avoid the unnecessary redeclarations of parameters.
A nonexhaustive list of places this is done:
markbind/src/lib/markbind/src/parser.js
Line 212 in 3591bc5
const element = node; |
markbind/src/lib/markbind/src/parser.js
Line 452 in 3591bc5
const element = node; |
markbind/src/lib/markbind/src/parser.js
Line 792 in 3591bc5
const element = node; |
and many others in componentParser.js