[英]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.