【问题标题】:Adding exceptions to esLint给 esLint 添加异常
【发布时间】:2016-12-14 22:36:37
【问题描述】:

我的 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",
  }
}

【问题讨论】:

    标签: javascript node.js webpack eslint


    【解决方案1】:

    假设引发错误的是 no-undef 规则,请将它们指定为 globals

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

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

    /*global path, persistentPlugins*/
    

    对于其他错误,有一个问题here 内联禁用它们。

    【讨论】:

    • 我相信这是“no-unused-vars”规则,因为我收到错误:` 3:8 error 'path' is defined but never used no-unused-vars` 当我转它的规则通过了。我需要为该规则指定一个案例吗?
    • 如果不使用,可以删除。但是,如果你只是想让错误消失,你可以disable specific eslint errors inline:/*eslint-disable no-unused-vars*/
    猜你喜欢
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2011-11-10
    • 2011-08-29
    相关资源
    最近更新 更多