【问题标题】:How to configure Eslint to ignore particular errors in Vue Cli 3 project如何配置 Eslint 以忽略 Vue Cli 3 项目中的特定错误
【发布时间】:2019-06-22 00:15:17
【问题描述】:

我在 Vue 项目中使用 Snap.svg,由 Vue cli 3 生成。 在 vue.config.js 中添加 Snap 如下:

module.exports = {
  chainWebpack: config => {
    config.module
      .rule("i18n")
      .resourceQuery(/blockType=i18n/)
      .type("javascript/auto")
      .use("i18n")
      .loader("@kazupon/vue-i18n-loader")
      .end();

    config.module
      .rule("snapsvg")
      .test(require.resolve("snapsvg"))
      .use("imports-loader?this=>window,fix=>module.exports=0")
      .loader("imports-loader")
      .end();

  }
};

以及 main.js

const snap = require(`imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js`);

我在没有本地导入的情况下在我的组件中使用 snap。

var s = Snap(this.paper["svg-wrap"]);

该库正常工作,生成了 svg,但是我不断收到 Eslint 错误。

error: 'Snap' is not defined (no-undef) at src\components\subpageBanner.vue:246:21:

我想在所有组件中继续使用 Eslint,但将其配置为忽略此类错误。 有可能吗?

【问题讨论】:

    标签: javascript vue.js eslint snap.svg


    【解决方案1】:

    如果它是单个文件,那么您可以将以下行放在文件的顶部。

    /*eslint no-undef: "warning"*/

    【讨论】:

    • 谢谢!这就是我需要的。根据 eslint 指南,我必须稍微修改它: /*eslint no-undef: 1*/ (0=off,1=warn,2=error)
    猜你喜欢
    • 2018-03-07
    • 2021-12-14
    • 2017-05-10
    • 2019-01-22
    • 2015-09-16
    • 2020-06-05
    • 2018-12-14
    • 2021-05-14
    • 2011-07-30
    相关资源
    最近更新 更多