向esLint添加例外

时间:2016-08-09 02:51:12

标签: javascript node.js webpack 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",
  }
}

1 个答案:

答案 0 :(得分:1)

假设no-undef规则引发了错误,请将其指定为globals

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

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

/*global path, persistentPlugins*/

对于其他错误,有关于内联禁用它们的问题here