最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VsCode not formatting TSJS files with single quotes - Stack Overflow

programmeradmin1浏览0评论

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.

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"
},
"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!!!

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.

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"
},
"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!!!

Share Improve this question asked Dec 9, 2019 at 6:26 Kevin192291Kevin192291 2,1175 gold badges30 silver badges45 bronze badges 2
  • Are you using prettier? – Jins Thomas Shaji Commented Dec 9, 2019 at 7:04
  • I am, and as you can see from the snippet, I have checked the settings in prettier to use single quotes – Kevin192291 Commented Dec 9, 2019 at 7:06
Add a ment  | 

2 Answers 2

Reset to default 7

From your settings file, it seems like you are using prettier for code formatting. In the latest updation, prettier changed reading configuration from mon settings file to a dedicated file for prettier settings. You can configure prettier via many options they've provided.

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

Example (JSON):

Create .prettierrc file, written in JSON or YAML, with optional extensions: .json/.yaml/.yml (without extension takes precedence).

.prettierrc

{
  "singleQuote": true
}

Then provide absolute path of .prettierrc file in settings.json (vscode settings file).

settings.json

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

Hope this helps!

The answer by Jins Thomas Shaji is very helpful. But except what he said, you also need to add a line in .prettierrc

"jsxSingleQuote": true

So, conclution:

.prettierrc

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

settings.json

"prettier.configPath": "./.prettierrc"
发布评论

评论列表(0)

  1. 暂无评论