在VS Code快速修复中,有没有办法将双引号更改为单引号?

Deb*_*ahK 4 visual-studio-code angular

当将VSCode与Angular结合使用时,我将导入语句写成这样:

import { AppComponent } from './app.component';
Run Code Online (Sandbox Code Playgroud)

VSCode快速修复将它们添加如下:

import { WelcomeComponent } from "app/home/welcome.component";
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以将VS Code设置更改为VS Code Quick Fix,以使用单引号而不是双引号?

小智 13

如果您的项目有.editorconfig文件,请尝试添加以下行:

[*]
...
quote_type = single
Run Code Online (Sandbox Code Playgroud)

我发现该.editorconfig文件似乎覆盖了 vscode、prettier、tslint 等的任何设置,并且似乎默认为单引号以外的其他设置。

如果您不需要该文件,也可以删除该文件。

有关editorconfig的更多信息。

  • 万一它可以节省其他人一些时间:这还行不通(至少对 2020 年 6 月在 VS Code 中的我来说),因为“quote_type”是一个[建议的想法](https://github.com/editorconfig/editorconfig/ wiki/EditorConfig-Properties#ideas-for-domain-specific-properties),但尚未成为官方财产。这是[功能提案](https://github.com/editorconfig/editorconfig/issues/410)。 (2认同)

Pen*_*gyy 9

检查您tslint.jsonquotemark零件。

如果它设置好的在使用doublequote

"quotemark": [
  true,
  "double"   < ------mention here
]
Run Code Online (Sandbox Code Playgroud)

那么typescript在使用singlequote. 这将导致 VS Code 的快速修复(为我显示修复选项)更改singlequotedoublequote.

所以解决方案应该double改为single.

"quotemark": [
  true,
  "single"   < ------change here
]
Run Code Online (Sandbox Code Playgroud)

  • 这是不准确的。此设置仅更改 lint 设置,不会更改 VS Code 的行为。 (9认同)

And*_*w E 7

这工作很好而且简单......

在 VSCode 中打开设置,例如 Command + ',',然后过滤“typescript”:

在此输入图像描述

寻找“引用样式”并更改:

在此输入图像描述


小智 5

您可以将Prettier Extension与以下设置一起使用(全局/工作区)。

"prettier.singleQuote": true
Run Code Online (Sandbox Code Playgroud)