我目前正在从Atom迁移到VS Code . 到目前为止,大多数事情在VS Code中完美运行 . 我唯一无法工作的是Prettier(代码格式化程序) .

在Atom和VS Code中,我安装了两个Prettier插件,并将它们保留为默认设置 .

每个项目都通过NPM包管理器包含Prettier,并通过'.prettierrc.json'和'.editorconfig'配置文件进行配置 . 除了Prettier之外,ESLint设置通过'.eslintrc.json'配置文件使用Prettier .

.prettierrc.json

{
    "parser": "flow",
    "printWidth": 100,
    "tabWidth": 4,
    "useTabs": true,
    "singleQuote": true
}

.editorconfig

# editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

.eslintrc.json

{
    "parser": "babel-eslint",
    "extends": ["plugin:prettier/recommended"],
    "plugins": ["prettier"],
    "rules": {
        "prettier/prettier": ["error"]
    },
    "env": {
        "es6": true,
        "browser": true,
        "jquery": true
    }
}

在Atom中,代码(示例)的格式如下(和首选方式):

import { Foundation } from 'foundation-sites/js/foundation.core';
Foundation.addToJquery($);

在VS Code中,代码的格式为不同的结构,并带有ESLint错误:

import {
    Foundation
} from 'foundation-sites/js/foundation.core';
Foundation.addToJquery($);

错误:

{
    "resource": "[project-folder]/src/assets/js/main.js",
    "owner": "eslint",
    "code": "prettier/prettier",
    "severity": 8,
    "message": "Replace `⏎↹Foundation⏎` with `·Foundation·` (prettier/prettier)",
    "source": "eslint",
    "startLineNumber": 19,
    "startColumn": 9,
    "endLineNumber": 21,
    "endColumn": 1
}

使用以下版本:eslint:5.6.0,eslint-config-prettier:3.1.0,eslint-plugin-prettier:2.6.2,更漂亮:1.14.3

有人知道如何配置VS Code或项目正确吗?