运行 上的 Vue 和 lint:如何配置?

Vue and lint on run: how to configure?

执行时npm run serve。我从 linter 收到了很多警告,我无法找到和配置

Module Warning (from ./node_modules/eslint-loader/index.js):
warning: Insert `;` (prettier/prettier) at src\main.js:1:22:
> 1 | import Vue from "vue"

例如,我的 VsCode 在 Prettier 扩展中设置为使用 4 space 作为选项卡,但是当 运行 相同的加载器警告我,因为它要我使用 2 spaces 缩进。

我无法确定在哪里/如何将 eslint-loader 本身配置为 config/disable 我需要的规则。

warning: Replace `····` with `··` (prettier/prettier) at src\main.js:22:1:
  20 | new Vue({
  21 |     router,
> 22 |     store,
     | ^
  23 |     render: h => h(App)
  24 | }).$mount("#app")

我想禁用它,例如,我想强制执行 4 space 缩进检查,而不是 2 spaces!

我有 Vetur 扩展程序,它被设置为使用 prettier

Prettier 设置为使用 4 spaces 选项卡。所以我认为我现在需要的设置与vscode无关。

最终解决方案- 致谢:https://eslint.vuejs.org/user-guide/#editor-integrations,我自己花了很多时间反复尝试

我在 vs code 上禁用了更漂亮的扩展并禁用了自动格式化。

我将此代码段添加到 workspace 配置(不是全局 !!!!)

{
    "eslint.validate": [
        {
            "language": "vue",
            "autoFix": true
        },
        {
            "language": "javascript",
            "autoFix": true
        },
        {
            "language": "javascriptreact",
            "autoFix": true
        }
    ],
    "eslint.autoFixOnSave": true,
    "editor.formatOnSave": false,
    "vetur.validation.template": false
}

此外,在 .eslintrc.js 文件上配置 prettier/prettier。

比如看我是怎么用的 prettier/prettier 就是 rules 部分:

module.exports = {
    root: true,
    env: {
        node: true
    },
    extends: [
        "plugin:vue/recommended",
        "eslint:recommended",
        "prettier/vue",
        "plugin:prettier/recommended",
    ],
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
        "prettier/prettier":[
            "error", 
            {
                "tabWidth"  : 4,
                "semi" : false,
            }
        ]
    },
    parserOptions: {
        parser: "babel-eslint"
    }
}

我在 VsCode 上安装了 prettier 和 eslint 扩展,如我的问题 post 所述。

See available options here: https://prettier.io/docs/en/options.html

通过这种方式,配置既可以在 vscode 上工作,也可以按照我的意愿作为 lint-on-运行 工作。

太棒了!