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

Kev*_*291 1 javascript typescript visual-studio-code prettier

在 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
Run Code Online (Sandbox Code Playgroud)

}

还有人处理这个吗?

谢谢!!!

Jin*_*aji 7

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

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

示例(JSON):

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

.prettierrc

{
  "singleQuote": true
}

Run Code Online (Sandbox Code Playgroud)

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

设置.json

...
"prettier.configPath": "./.prettierrc"
...
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!