简体   繁体   English

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

[英]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:安装 EsLint 后出现的错误之一如下:

Prop spreading is forbiddeneslint(react/jsx-props-no-spreading)道具传播是禁止的(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.我想在 EsLint 配置中创建一个规则来忽略此错误,但我发现的示例不起作用。

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.谢谢你。

Try turning off the "react/jsx-props-no-spreading" rule:尝试关闭"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
  }
};

As an example if there is not so much errors you can ignore them by // eslint-disable-next-line例如,如果没有太多错误,您可以通过// eslint-disable-next-line忽略它们

Or you can write for concrete error like或者你可以写具体的错误,比如

// eslint-disable jsx-props-no-spreading

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM