当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。

在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。

我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)

如何定制VSCode来避免这种情况?


当前回答

我使用的是typescript,对我来说,它在更漂亮的设置下检查“Tslint集成”标志得到了解决(在vscode首选项中):

其他回答

安装更漂亮的扩展和粘贴下面的代码在你的VSCode设置。json文件

 "prettier.useEditorConfig": false,
 "prettier.singleQuote": true

这将忽略您的.editorconfig文件设置。

对我有用的是设置。prettierrc。Json配置文件。把它放在你的项目的根,像这样的示例配置:

{
  "singleQuote": true,
  "trailingComma": "all",
  "tabWidth": 2,
  "semi": true,
  "arrowParens": "always"
}

触发Format Document命令后,一切都能正常工作。

旁注:这个解决方案的一个好处是,由于目前的配置文件,每个团队成员都获得了相同的格式化输出。

我没有安装更漂亮的扩展,但在阅读可能重复的答案后,我从头开始添加在我的用户设置(用户设置。json, Ctrl+,快捷方式):

"prettier.singleQuote": true

部分有绿色警告(未知配置设置),单引号不再被替换。

我怀疑更漂亮的扩展是不可见的,但嵌入在Vetur扩展。

首先,安装Prettier扩展。在项目的根目录下创建一个. pretierrc配置文件。并添加如下配置:

{ trailingComma:“es5”, singleQuote:真的, jsxSingleQuote:真的, printWidth: 100, tabWidth: 2, “春天”:真的, “endOfLine”:“auto” 的

我解决这个问题的方法是通过安装禁用eslint中的所有格式化规则 npm i -D eslint-config-prettier,然后在eslint配置文件的extends数组的末尾添加“prettier”

module.exports = {
  env: {
    node: true,
  },
  extends: [
    'airbnb-base',
    'airbnb-typescript/base',
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'prettier',

  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  plugins: ['@typescript-eslint'],
  root: true,
};

然后把它作为我的默认格式化器做得更漂亮