Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable in EsLint "react / jsx-props-no-spreading" error in Reactjs

After installing EsLint one of the errors that appears to me is the following:

Prop spreading is forbiddeneslint(react/jsx-props-no-spreading)

I want to create a rule in the EsLint configuration to ignore this error but the examples I found do not work.

This is the format to create a global exception:

...
"react/jsx-props-no-spreading": [{
    "html": "ignore" / "enforce",
    "custom": "ignore" / "enforce",
    "exceptions": [<string>]
}]
...

And this is the format to create an exception in a specific file:

{
  "rules": {...},
  "overrides": [
    {
      "files": ["*-test.js","*.spec.js"],
      "rules": {
        "no-unused-expressions": "off"
      }
    }
  ]
}

And here, the code that I currently have:

module.exports = {
  extends: "../../.eslintrc.js",
  rules: {
    "import/no-extraneous-dependencies": ["error",  {"devDependencies": true}]
  },
  env: {
    "jest": true
  }
};

At the moment, I just keep giving the same error continuously.

Thank you.

like image 931
Victoria Diro Avatar asked Sep 30 '19 11:09

Victoria Diro


People also ask

How do you fix prop spreading is forbidden react JSX props no spreading?

The warning "Props spreading is forbidden" is caused when we use the spread syntax to unpack a props object when passing props to a component. To get around the warning, disable the eslint rule.

How do I disable ESLint errors in react?

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console. /* eslint-disable */ console.

How do I turn off ESLint rule?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

How do I disable ESLint on next line?

disable warnings eslint Use /* eslint-disable */ to ignore all warnings in a file. You may use special comments to disable some warnings. Use // eslint-disable-next-line to ignore the next line. Use /* eslint-disable */ to ignore all warnings in a file.


2 Answers

Try turning off the "react/jsx-props-no-spreading" rule:

module.exports = {
  extends: "../../.eslintrc.js",
  rules: {
    "import/no-extraneous-dependencies": ["error",  {"devDependencies": true}],
    "react/jsx-props-no-spreading": "off",
  },
  env: {
    "jest": true
  }
};
like image 87
uneet7 Avatar answered Sep 20 '22 11:09

uneet7


As an example if there is not so much errors you can ignore them by // eslint-disable-next-line

Or you can write for concrete error like

// eslint-disable jsx-props-no-spreading
like image 27
Sabit Rakhim Avatar answered Sep 16 '22 11:09

Sabit Rakhim