简体   繁体   English

VsCode 不使用单引号格式化 TS/JS 文件

[英]VsCode not formatting TS/JS files with single quotes

After one of the latest updates to VS Code, when pressing Ctrl+Shift+F In windows, it is auto formattig all of my code with double instead of single quotes despite my setting it to only use single quotes.在 VS Code 的最新更新之一之后,在 Windows 中按 Ctrl+Shift+F 时,尽管我将其设置为仅使用单引号,但它会自动使用双引号而不是单引号格式化我的所有代码。

Here is my settings file:这是我的设置文件:

{
"[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.updateImportsOnFileMove.enabled": "always",
"[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"atlascode.jira.workingSite": {
    "baseUrlSuffix": "atlassian.net"
},
"yaml.schemas": {
    "file:///c%3A/Users/kevin/.vscode/extensions/atlassian.atlascode-2.1.5/resources/schemas/pipelines-schema.json": "bitbucket-pipelines.yml"
},
"window.zoomLevel": -1,
"[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"git.autofetch": true,
"javascript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single",
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true

} }

Is anyone else dealing with this?还有人处理这个吗?

Thanks!!!谢谢!!!

From your settings file, it seems like you are using prettier for code formatting.从您的设置文件来看,您似乎正在使用更漂亮的代码格式。 In the latest updation, prettier changed reading configuration from common settings file to a dedicated file for prettier settings.在最新的更新中,prettier 将读取配置从通用设置文件更改为用于更漂亮设置的专用文件。 You can configure prettier via many options they've provided.您可以通过他们提供的许多选项配置更漂亮。

https://prettier.io/docs/en/configuration.html https://prettier.io/docs/en/configuration.html

Example (JSON):示例(JSON):

Create .prettierrc file, written in JSON or YAML, with optional extensions: .json/.yaml/.yml (without extension takes precedence).创建.prettierrc文件,用 JSON 或 YAML 编写,带有可选的扩展名:.json/.yaml/.yml(无扩展名优先)。

.prettierrc .prettierrc

{
  "singleQuote": true
}

Then provide absolute path of .prettierrc file in settings.json (vscode settings file).然后在settings.json (vscode 设置文件)中提供.prettierrc文件的绝对路径。

settings.json设置.json

...
"prettier.configPath": "./.prettierrc"
...

Hope this helps!希望这可以帮助!

The answer by Jins Thomas Shaji is very helpful. Jins Thomas Shaji 的回答非常有帮助。 But except what he said, you also need to add a line in .prettierrc但是除了他说的,你还需要在.prettierrc中添加一行

"jsxSingleQuote": true

So, conclution:所以,结论:

.prettierrc .prettierrc

{
"singleQuote": true, 
"jsxSingleQuote": true,
}

settings.json设置.json

"prettier.configPath": "./.prettierrc"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 非 js/ts 文件的 vscode“智能感知”和“转到定义” - vscode "Intellisense" and "Go to definition" for not js/ts files 类型检查无法与.ts文件上的VsCode一起使用 - Typechecking not working with VsCode on .ts files 如何在 VSCode 中的同一项目中的 .ts 文件和 .js 文件上运行 typescript-eslint - How to run typescript-eslint on .ts files and eslint on .js files in the same project in VSCode 关闭 .JS /.JSX 文件的 VSCode Typescript 错误并为.TS /.TSX 文件保留它们? - Turn off VSCode Typescript Errors for .JS / .JSX files & keep them for .TS / .TSX files? vscode:摆脱 js 和 ts 文件中的消息:“导出的标识符应该有注释或未导出” - vscode: get rid of message in js and ts files: 'exported identifier should have comment or be unexported' VSCode 自动补全 function *和方法*括号(js/ts) - VSCode autocomplete function *and method* parentheses (js/ts) 在JS中用双引号替换单引号 - Replacing single quotes with double quotes in JS 无法使用--out将打字稿模块(.ts)文件合并为单个输出(.js)文件注释:出现错误 - Unable to concat typescript modules (.ts) files into single output(.js) using --out Comment: Getting Error 我可以使用TSCode声明TS界面以用于普通JS项目吗? - Can I declare TS interfaces for use in plain JS projects with VSCode? VSCODE 跳转到JS文件定义(不是.d.ts文件) - VSCODE Jump to the JS file definition (not the .d.ts file)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM