Prettier in VS Code - Format double quotes inside double quotes

↘锁芯ラ 提交于 2020-07-23 08:04:45

问题


I'm using the extension Prettier in VS Code. I want double quotes in the code. The "jsxSingleQuote" and "singleQuote" are set to false.

When I run format on this line of code

var hello = "\"hello\"";

Prettier formats it to:

var hello = '"hello"';

I want to keep double quotes and the line of code should not be formatted!

Here are the settings:

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

回答1:


This is as intended. From https://github.com/prettier/prettier/tree/21733e441dc01f7d85b483edee92b7e7507bfd9a#quotes:

  • If the number of quotes outweighs the other quote, the quote which is less used will be used to format the string - Example: "I'm double quoted" results in "I'm double quoted" and "This "example" is single quoted" results in 'This "example" is single quoted'.


来源:https://stackoverflow.com/questions/62595498/prettier-in-vs-code-format-double-quotes-inside-double-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!