11

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.

Milo
  • 3,002
  • 9
  • 25
  • 40
Victoria Diro
  • 123
  • 1
  • 1
  • 4

2 Answers2

27

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
  }
};
uneet7
  • 2,012
  • 3
  • 17
  • 34
  • 2
    Yes, just dialing "off" is deactivated, thank you very much for your advice – Victoria Diro Sep 30 '19 at 14:17
  • Since this answer received a lot of attention than what I expected, Please NOTE that props spreading is an [anti pattern](https://codeburst.io/react-anti-pattern-jsx-spread-attributes-59d1dd53677f) and is highly discouraged – uneet7 Feb 18 '21 at 12:15
3

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
Sabit Rakhim
  • 351
  • 1
  • 10
  • Is this line valid for the whole file or is it turning off the check only for the following line? – FMaz008 Dec 12 '20 at 23:46
  • @FMaz008, sorry for late response. eslint-disable valid for whole file depend on line which is starts(f.e. from 5 line till the end). In case of eslint-disable-next-line it's only has effect on 1 line – Sabit Rakhim Jan 11 '21 at 08:41