How to forbid edition of arguments of a function, expect Array.reduce accumulator

28 views Asked by At

I did not find a documentation in the whole eslint website, and I do not know if there is a plugin to forbid arguments editions.

Here is an example of code which should be:

Incorrect:

const incorrectUpdate = (data) => {
  data.field = data.field === 'Hello' ? 'Stack' : 'Overflow';
  return data;
};

Correct:

const validUpdate = (data) => {
  return { ...data, field: data.field === 'Hello' ? 'Stack' : 'Overflow' };
};

Please can you send me the eslint config?

Can you left Array.reduce to continue accumulator edition ?

1

There are 1 answers

0
karkael On BEST ANSWER

Activate no-param-reassign.

For Array.reduce, use every time the same variable name: "acc".

Here is the config, in .eslintrc:

"no-param-reassign": [
  "warn",
  {
    "props": true,
    "ignorePropertyModificationsFor": ["acc"]
  }
],