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

牧云@^-^@ 提交于 2019-11-30 21:50:21

问题


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):

  • 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

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.

Any help would be greatly appreciated.


回答1:


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

To change it, open your user settings file

Ctrl+Shift+P and type Open User Settings.

Search for prettier.singleQuote and change it to true like

"prettier.singleQuote": true




回答2:


Daniel B's solution didnt help my case, I needed to follow this: 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


Edit: one more thing, I noticed after testing that my issue seemed to boil down to the formatter. I updated my typescript formatter to this:
"[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



来源:https://stackoverflow.com/questions/47091719/vs-code-auto-indent-code-formatting-changes-single-quotation-marks-to-double

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!