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

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

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

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


当前回答

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

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}],
  }
}

其他回答

你可以在settings.json中使用它

"javascript.preferences.quoteStyle": "single"

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

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

[*]
quote_type = single

看起来这个问题有一个漏洞:更漂亮的漏洞

以上方法对我都没用。 唯一有效的是,在package.json中添加这行代码:

"prettier": {
    "singleQuote": true
  },

对于JSX使用:

{"jsxSingleQuote": false}
quote_type = single

将此添加到.editorconfig中

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
quote_type = single