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

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

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

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


当前回答

我在控制毛边和更漂亮的排版方面有很多问题。我有自己的规矩,让自己看起来更漂亮

"prettier/prettier": [
      "error",
      { "singleQuote": true, "trailingComma": "none" }
    ],

和。prettierrc文件中的规则

{
  "tabWidth": 2
}

但是我的.prettierrc文件没有得到处理。我的解决方案是在开发依赖中安装prettier作为一个包。所以对我有效的解决方案是安装所有这些包eslint-config-prettier eslint-plugin-prettier and prettier。

其他回答

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

"prettier.singleQuote": true

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

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

After struggling with the issue I found a useful tool. If you click on the Prettier word in the right lower corner you will get the Output window opened. In that window once you run formatting (in my case it is Alt + Shift + F) you will see all the configurations which prettier will use to format the document. So, we can clearly see that specifying the prettier in the prettier.singleQuote is wrong. It should just be singleQuote. Hence, having the .prettierrc file in my user root folder with the following contents produced the desired result:

{
    "trailingComma": "none",
    "useEditorConfig": false,
    "singleQuote": true
}

此外,请确保已安装了Prettier扩展。

对于默认使用.editorconfig文件的项目。格式化程序将忽略设置中的规则并使用.editorconfig中的规则,然后您可以:

删除.editorconfig文件,并使用VSCode设置。 根据您的文件类型,在.editorconfig文件中添加quote_type = single。也可以将quote_type value设置为double或auto。

从vuejs/vetur发行页面https://github.com/vuejs/vetur/issues/986# 这个解决方案对我很有效。

在vcodes设置中。Json文件添加此条目

"vetur.format.defaultFormatterOptions": {
    "prettier": {
        "singleQuote": true
    }
},

好吧,就像那个家伙(@user2982122)提到的,但不是文件,而是代码->首选项->设置,然后寻找引用,选择更漂亮,并勾选两个框