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

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

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

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


当前回答

如果你使用的是YAML插件,它还有一个单引号/双引号选项,这让我很困惑。欢呼。

其他回答

撰写本文时(2022年6月):

请考虑.editorconfig在最后覆盖所有其他配置,找到该文件(很可能在项目的根目录上),编辑它并添加以下内容:

[*]
quote_type = single

我在项目文件夹中添加了一个名为。pretierrc的文件。 文件内容:

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

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

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

这对我来说很管用: 尝试右键单击当前文档 然后选择format document with, 并为文档选择自己的格式扩展。 :)

在我的情况下,问题是在转义\字符内的字符串:

message = 'Error argument is not an object, it\'s ' + typeof error

打开avoidEscape选项并对该字符串使用双引号解决了问题:

message = "Error argument is not an object, it's " + typeof error

.eslintrc.js

module.exports = {
  rules : {
    // Other rules...
    'quotes' : ['error', 'single', {'avoidEscape' : true}],
  }
}