问题
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