typescript VS Code Auto Indent / Code Formatting 将单引号改为双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47091719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:00:32  来源:igfitidea点击:

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

angulartypescriptformattingvisual-studio-codeindentation

提问by Johannes Piontkowitz

I am using VS Code 1.17.2 with the following extensions installed (Unfortuanetly i can't link them since i don't have enought reputation):

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

  • Angular 5 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout
  • Angular Essentials
  • Angular Language Service
  • Angular v5 TypeScript Snippets
  • angular2-inline
  • Auto Import
  • Debugger for Chrome
  • EditorConfig for VS Code (since Angular Essentials depends on it)
  • HTML Snippets
  • IntelliSense for CSS class names
  • Material Icon Theme
  • Path Intellisense
  • PHP IntelliSense
  • Prettier - Javascript formatter
  • TSLint
  • Visual Studio Team Services
  • vscode-icons
  • Winter Is Coming Theme
  • Angular 5 Snippets - TypeScript、Html、Angular Material、ngRx、RxJS 和 Flex 布局
  • 角度要点
  • Angular 语言服务
  • Angular v5 TypeScript 片段
  • angular2-inline
  • 自动导入
  • Chrome 调试器
  • VS Code 的 EditorConfig(因为 Angular Essentials 依赖于它)
  • HTML 片段
  • 用于 CSS 类名称的 IntelliSense
  • 材质图标主题
  • 路径智能感知
  • PHP智能感知
  • Prettier - Javascript 格式化程序
  • TSLint
  • Visual Studio 团队服务
  • vscode-icons
  • 冬天来了主题

When auto formatting a TypeScript file (Shift + Alt + F), it does the indent right, but it also changes all single quotation marks to double quotation marks, which makes TSLint complain. I am pretty certain the auto indent is not supposed to do that and it really is annoying.

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

Any help would be greatly appreciated.

任何帮助将不胜感激。

回答by Daniel B

The extensions uses the settings that are set in your VS Code user settings file.

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

To change it, open your user settings file

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

Ctrl+Shift+Pand type Open User Settings.

Ctrl+ Shift+P和类型Open User Settings.

Search for prettier.singleQuoteand change it to true like

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

"prettier.singleQuote": true

"prettier.singleQuote": true

回答by Sam

Daniel B's solution didnt help my case, I needed to follow this: https://github.com/praveenpuglia/angular-sanity/issues/4

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:

VS代码

VSCode 中的自动导入智能使用 tslint.json 文件,以便根据您的配置插入导入语句。但是,如果您手动编写 import 语句并且不小心弄乱了它,那么这里有一件需要拯救的事情。

在用户首选项中设置以下内容:

"tslint.autoFixOnSave": true



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

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

after I updated the formatter that - I believe - helped fix the part that was incorrectly updating my code to double quotes

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