Vetur/Eslint/VS Code - 无法在 .vue 文件的括号之间设置空格

Egg*_*gon 5 eslint vue.js visual-studio-code vetur

我不知道如何为函数括号之间的空间设置配置。我已经设置了处处为 true,但是当我保存.vue文件时,该空间被删除 - 删除后,它会突出显示为错误 ( Missing space between function parentheses)。它发生在script部分。在.js文件空间添加,但突出显示为错误,这一次... Unexpected space between function parentheses?!在保存空间时,有一些设置配置(我现在无法重新创建),然后在.vue文件中再次删除了空间。

我的设置.json

"vetur.format.defaultFormatter.js": "prettier", // tried both prettier and typescript
// "vetur.format.defaultFormatter.js": "vscode-typescript", // tried both prettier and typescript
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
"vetur.format.defaultFormatterOptions": {
    "prettier": {
        "singleQuote": true,
        "spaceBeforeFunctionParen": true,
        "eslintIntegration": true,
    },
    "vscode-typescript": {
        "singleQuote": true,
        "spaceBeforeFunctionParen": true,
        "eslintIntegration": true,
    }
},
Run Code Online (Sandbox Code Playgroud)

.eslintrc.js

module.exports = {
    root: true,
    env: {
        node: true
    },
    'extends': [
        'plugin:vue/essential',
        '@vue/standard'
    ],
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',          
        "space-before-function-paren": ["error", "always"], //setting this to 'never' removes the error highlight in vue files, not js files
    },
    parserOptions: {
        parser: 'babel-eslint',
        sourceType: "module"
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经阅读了无数的问题,并在我在答案中找到的每个可能的设置中设置了函数括号之间的空格。linting 过程仍然会找到一种方法来忽略所有这些设置并实现不同的设置。更不用说它突出显示了与自动格式化不一致的错误。有没有我仍然缺少的其他设置?

Cor*_*ius 3

尝试这个:

npm install prettier@v1.19.1 --save-dev --save-exact
Run Code Online (Sandbox Code Playgroud)

然后重新启动VS Code。

Prettier 最近刚刚更新到 v2,如果您的项目本地没有安装 Prettier,它将使用 VS Code 的版本,这很可能是最新版本。在 prettier v2 中,space-before-function-paren已成为默认值,因此将应用于所有未安装本地版本的 prettier pre v2 的项目。对我来说,使用任何配置组合似乎都不起作用 - 就像 prettier 忽略了所有这些。希望这可以帮助。