【问题标题】:VsCode not formatting TS/JS files with single quotesVsCode 不使用单引号格式化 TS/JS 文件
【发布时间】:2020-04-02 05:49:14
【问题描述】:

在 VS Code 的最新更新之一之后,当在 windows 中按 Ctrl+Shift+F 时,它是自动的 尽管我将其设置为仅使用单引号,但我将所有代码格式化为双引号而不是单引号。

这是我的设置文件:

{
"[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

}

还有其他人在处理这个吗?

谢谢!!!

【问题讨论】:

  • 你用的是prettier吗?
  • 我是,从sn-p可以看出,我已经检查了prettier中的设置以使用单引号

标签: javascript typescript visual-studio-code prettier


【解决方案1】:

Jins Thomas Shaji 的回答非常有帮助。但是除了他说的,你还需要在.prettierrc中添加一行

"jsxSingleQuote": true

所以,结论:

.prettierrc

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

settings.json

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

【讨论】:

    【解决方案2】:

    从您的设置文件来看,您似乎正在使用更漂亮的代码格式化。 在最新的更新中,prettier 将读取配置从通用设置文件更改为 prettier 设置的专用文件。您可以通过他们提供的许多选项来配置更漂亮。

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

    示例(JSON):

    创建.prettierrc 文件,用 JSON 或 YAML 编写,带有可选扩展名:.json/.yaml/.yml(无扩展名优先)。

    .prettierrc

    {
      "singleQuote": true
    }
    
    

    然后在settings.json(vscode设置文件)中提供.prettierrc文件的绝对路径。

    settings.json

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多