VS Code 即使在设置更新后仍对字符串使用单引号

VS Code keeps using single quotes for string even after settings update

提问人:manymanymore 提问时间:7/7/2022 更新时间:7/7/2022 访问量:485

问:

如何配置 VS Code,使其在设置文档格式时将所有单引号更改为双引号?我在设置中搜索了关键字,并尽可能地选择了双引号:quotes

enter image description here enter image description here enter image description here

但结果是文件格式化时没有更改引号。即,格式化后,单引号保持单引号,双引号保持双引号。

我说的是 .js 文件。

visual-studio-code 设置 字符串格式引

评论


答:

1赞 Timothy G. 7/7/2022 #1

您似乎已经安装了更漂亮的设备(基于屏幕截图中的选项),这可能会覆盖您的设置。当您保存/格式化时,您可能会在更漂亮的输出中看到如下内容:

["INFO" - 9:28:24 AM] Formatting file:///c%3A/dev/GitHub/project/src/root.tsx
["INFO" - 9:28:24 AM] Using config file at 'c:\dev\GitHub\project\.prettierrc'
["INFO" - 9:28:24 AM] Using ignore file (if present) at c:\dev\GitHub\project\src\.prettierignore
["INFO" - 9:28:24 AM] File Info:
{
  "ignored": false,
  "inferredParser": "typescript"
}
["INFO" - 9:28:24 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 9:28:24 AM] Prettier Options:
{
  "filepath": "c:\\dev\\GitHub\\project\\src\\root.tsx",
  "parser": "typescript",
  "useTabs": false,
  "printWidth": 120,
  "tabWidth": 2,
  "endOfLine": "auto",
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSameLine": false
}
["INFO" - 9:28:24 AM] Formatting completed in 0.061ms.

请注意零件以及输出中的零件。如果您有一个 .prettierrc 文件,请修改它并将其设置为 。保存文件,重启 Visual Studio Code,然后重试。"singleQuote": true,Detected local configuration (i.e. .prettierrc or .editorconfig)singleQuotefalse

评论

0赞 manymanymore 7/7/2022
我有一个文件,我什至不知道它正在覆盖设置。删除该文件解决了该问题。该文件已在 Prettier 输出中报告。.prettierrc
0赞 Timothy G. 7/7/2022
@manymanymore删除该文件可能会使其回退到使用 VS Code 的设置,这似乎是您所追求的。在我们的存储库中,我相信这个文件已经签入,所以删除它会影响其他开发人员,但如果这不是你的设置,你会没事的!