【问题标题】:Ignore specific error for eslint in the whole project忽略整个项目中 eslint 的特定错误
【发布时间】:2018-03-07 08:14:53
【问题描述】:

我正在使用 AdonisJs(NodeJS 框架),他们创建了一个名为 use 的函数来导入文件,就像它们是命名空间一样,例如 use('App/Services/User') 而不是 require('../app/Services/User')

问题是eslint会抛出错误'use' is not defined no-undef

此时我有两种方式:

  1. 在每个文件中添加一个 eslint 注释来禁用该行的警报,但这很烦人
  2. 使用require而不是use,但是这个功能非常有用。

有没有办法为整个项目中的use 功能禁用“一次性”特定的no-undef

【问题讨论】:

    标签: node.js eslint adonis.js


    【解决方案1】:

    查看.eslintrc 配置中的globals 部分。

    {
        "globals": {
            "use": false
        }
    }
    

    【讨论】:

      【解决方案2】:

      您可以在您的.eslintrc.json 上配置您的eslint 在他们的官方页面上参考:https://eslint.org/docs/user-guide/configuring

      对于no-undef规则,可以在配置中添加全局

      {
          "globals": {
              "var1": true,
              "var2": false
          }
      }
      

      也在他们的文档中指定:https://eslint.org/docs/user-guide/configuring#specifying-globals

      【讨论】:

        猜你喜欢
        • 2019-06-22
        • 2017-05-10
        • 2015-09-16
        • 1970-01-01
        • 1970-01-01
        • 2021-07-28
        • 1970-01-01
        • 1970-01-01
        • 2021-05-13
        相关资源
        最近更新 更多