VS 代码自动缩进/代码格式将单引号更改为双引号

VS Code Auto Indent / Code Formatting changes single quotation marks to double

我正在使用安装了以下扩展的 VS Code 1.17.2(不幸的是我不能 link 它们,因为我没有足够的声誉):

当自动格式化 TypeScript 文件时(Shift + Alt + F),它会正确缩进,但也会将所有单引号更改为双引号,这让 TSLint 抱怨。我很确定自动缩进不应该这样做,这真的很烦人。

如有任何帮助,我们将不胜感激。

扩展使用在您的 VS Code 用户设置文件中设置的设置。

要更改它,请打开您的用户设置文件

Ctrl+Shift+P 并输入 Open User Settings.

搜索 prettier.singleQuote 并将其更改为 true like

"prettier.singleQuote": true

Daniel B 的解决方案对我的情况没有帮助,我需要遵循以下步骤: https://github.com/praveenpuglia/angular-sanity/issues/4

VSCode

Auto imports are intelligent in VSCode to use tslint.json file in order to insert import statements based on your configuration. But if you are manually writing import statement and accidentally mess that up here's one thing to rescue.

In User Preferences set the following:

"tslint.autoFixOnSave": true


编辑:还有一件事,我在测试后注意到我的问题似乎归结为格式化程序。我将我的打字稿格式化程序更新为:

"[typescript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
}

在我更新格式化程序之后 - 我相信 - 帮助修复了错误地将我的代码更新为双引号的部分