在 EsLint 中禁用 Reactjs 中的“react / jsx-props-no-spreading”错误

Vic*_*iro 13 reactjs eslint redux

安装 EsLint 后,我​​看到的错误之一如下:

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>]
}]
...
Run Code Online (Sandbox Code Playgroud)

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"
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

And here, the code that I currently have:

module.exports = {
  extends: "../../.eslintrc.js",
  rules: {
    "import/no-extraneous-dependencies": ["error",  {"devDependencies": true}]
  },
  env: {
    "jest": true
  }
};
Run Code Online (Sandbox Code Playgroud)

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

Thank you.

une*_*et7 31

尝试关闭"react/jsx-props-no-spreading"规则:

module.exports = {
  extends: "../../.eslintrc.js",
  rules: {
    "import/no-extraneous-dependencies": ["error",  {"devDependencies": true}],
    "react/jsx-props-no-spreading": "off",
  },
  env: {
    "jest": true
  }
};
Run Code Online (Sandbox Code Playgroud)

  • 是的,只需拨打“关闭”即可停用,非常感谢您的建议 (2认同)
  • 由于这个答案受到了比我预期更多的关注,请注意道具传播是一种[反模式](https://codeburst.io/react-anti-pattern-jsx-spread-attributes-59d1dd53677f)并且高度灰心 (2认同)

小智 5

举个例子,如果没有那么多错误,你可以忽略它们 // eslint-disable-next-line

或者你可以写具体的错误,例如

// eslint-disable jsx-props-no-spreading
Run Code Online (Sandbox Code Playgroud)