【问题标题】:vue-cli eslint not catching errorsvue-cli eslint 没有捕获错误
【发布时间】:2020-10-27 23:22:34
【问题描述】:

我正在尝试为我的新 vue cli 项目设置 eslint。它不起作用。它通过了,但我没有发现我有意添加的错误。任何想法我做错了什么?

vue.config.js

  devServer: {
    overlay: {
      warnings: true,
      errors: true,
    },
  },
  lintOnSave: true,

.eslintrc.js

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  parserOptions: {
    parser: "babel-eslint",
  },
  extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
  plugins: ["prettier"],
  // add your custom rules here
  rules: {
    semi: "error",
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
  },
};

src/App.vue:

...
methods: {
  test() {
    return true;
  },
},
...

vue-cli-service lint 结果:

> project@0.1.0 lint /project/location/component_library
> vue-cli-service lint

 DONE  No lint errors found!

【问题讨论】:

    标签: javascript vue.js vue-cli


    【解决方案1】:

    由于它是 vue-cli 项目,如果您使用的是 vue-cli-ui,请转到 'Plugins' => 'Add Plugin' 并在 vue-cli 插件页面上搜索并安装 eslint-plugin-vue。它简化了很多,易于使用,使用正确的选项管理 linting。在安装后屏幕上,选择 eslint-type (prettier, airbnb etc) (要么) 您可以将解析器设置为vue-eslint-parser,将解析器选项设置为babel-eslint

    或者,如果您不使用 vue-cli 服务,这是使用 eslint-plugin-vue 的最小配置集,请将其添加到 .eslintrc.js 文件中。

    module.exports = { 
      root: true,
      env: {
        browser: true,
        node: true
      },
      extends: [
        'plugin:vue/strongly-recommended',
        'plugin:vue/essential',
        '@vue/prettier', //recommended use @vue/airbnb
    
      ],
      // add your custom rules here
      rules: {
        //"semi": "error",
        //"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
        //"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
        //"no-unused-vars": process.env.NODE_ENV === "production" ? "error" : "off",
        //"vue/no-side-effects-in-computed-properties": "off",
        //"vue/no-async-in-computed-properties": "off",
       
      }, 
      parser: "vue-eslint-parser",
      parserOptions: {
        parser: "babel-eslint",
        "sourceType": "module"
      },
      plugins: [
        //plugins list
      ],
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-14
      • 2020-06-05
      • 2020-09-01
      • 2018-11-23
      • 2021-02-13
      • 2021-05-02
      • 2019-01-23
      • 2019-12-17
      • 2013-03-14
      相关资源
      最近更新 更多