Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override eslint rule to "no-param-reassign": ["error", { "props": false }] #1065

Closed
openorclose opened this issue Feb 28, 2020 · 0 comments · Fixed by #1075
Closed

Override eslint rule to "no-param-reassign": ["error", { "props": false }] #1065

openorclose opened this issue Feb 28, 2020 · 0 comments · Fixed by #1075

Comments

@openorclose
Copy link
Contributor

openorclose commented Feb 28, 2020

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:

const element = node;

const element = node;

const element = node;

and many others in componentParser.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants