向 esLint 添加异常

Adding exceptions to esLint

我的 webpack 配置中有两个变量,它们是必需的,但会引发 linting 错误。

有没有办法为特定变量添加例外?

我想忽略 pathpersistentPlugins

当前的 .eslintrc 文件如下所示:

{
  "parser": "babel-eslint",
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "globals": {
    "React": false,
    "react": false,
  },
  "plugins": [
    "react"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended"
  ],
  "rules": {
    "no-console": 0,
    "no-underscore-dangle": 1,
    "quotes": [2, "single"],
    "react/no-danger": "off",
  }
}

假设它是 no-undef rule that's raising the error, specify them as globals:

...
"globals": {
  "path": true,
  "persistentPlugins": true,
  "React": false,
  "react": false,
},
...

或者,您可以在 webpack 配置中禁用内联错误:

/*global path, persistentPlugins*/

对于其他错误,有一个问题如何禁用它们。