VS代码更漂亮-在双引号内设置双引号格式

时间:2020-06-26 13:12:25

标签: visual-studio-code prettier

我在VS Code中使用扩展Prettier。我想要在代码中使用双引号。 “ jsxSingleQuote”和“ singleQuote”设置为false。

当我在此行代码上运行格式

var hello = "\"hello\"";

漂亮的将其格式化为:

var hello = '"hello"';

我想保留双引号,并且不应格式化代码行!

以下是设置:

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "..../app.js",
  "parser": "babel"
}

2 个答案:

答案 0 :(得分:1)

这是预期的。来自https://github.com/prettier/prettier/tree/21733e441dc01f7d85b483edee92b7e7507bfd9a#quotes

  • 如果报价数量大于其他报价,则报价为 较少使用的字符串将用于格式化字符串-例如:“我是双重的 引号”的结果为“我被双引号”,而“此“示例”为 单引号”将导致“此“示例”被单引号”。

答案 1 :(得分:0)

尝试在根级别创建文件.prettierrc,即同级package.json,并将属性singleQuote设置为true,如下所示:

{
  "singleQuote": true
}