如何将 eslint 规则用于 no-multi-comp

How to use eslint rule for no-multi-comp

我遇到了这个 style guide 并试图采用它的一些规则。

第一条规则提到

Only include one React component per file. However, multiple Stateless, or Pure, Components are allowed per file. eslint: react/no-multi-comp.

所以在我的 .eslintrc

{
    "parser": "babel-eslint",
    "plugins": [
        "react"
    ],
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "rules": {
       "no-set-state": "off"
    },

    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
          "jsx": true,
          "modules": true
      }
  },
  "globals": {
    "localStorage": true,
    "fetch": true
},
  "settings": {
    "react": {
        "pragma": "React",
        "version": "16.4.1"
    }
    }
}

我将此添加到 rules

"rules": {
   "no-set-state": "off",
   "react/no-multi-comp":  [true, { "ignoreStateless": true }]
},

我这样做正确吗?因为当我阅读 docs 时,我看到一个 <enabled> 我不知道那是什么意思。

使用 Visual Studio 代码,并安装 ESLint 插件,您应该可以在 Output > ESLint

下查看

<enabled> 正在寻找 0、1 或 2。

相应更改。

<enabled> 查找 0,1,2 之一或 off,warn,error 之一的值,意思是:

来自docs

"off" or 0 - turn the rule off

"warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

"error" or 2 - turn the rule on as an error (exit code is 1 when
triggered)