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

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

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

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


当前回答

使用这个扩展。

https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes

cmd ' (ctrl '在win/Linux上)将在' ' '中循环

其他回答

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

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

对于JSX使用:

{"jsxSingleQuote": false}

你可以在settings.json中使用它

"javascript.preferences.quoteStyle": "single"

对我来说,这两种选择都解决了问题:

通过在。prettierrc - "singleQuote": true中添加 或者在包中添加以下内容。json - - - > "漂亮":{ “singleQuote”:真的 }

虽然我也尝试添加.prettierrc.js和有以下

module。导出= { singleQuote: true };

这并没有起作用。

对我来说唯一有效的方法是: 并且仅适用于Angular项目:

开始你的项目吧。”Editorconfig "文件,并粘贴'quote_type = single'。 希望这对你也有用。