Reputation: 345
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"
}
Upvotes: 2
Views: 1816
Reputation: 5044
Yeah, "working as intended", but doesn't fix your problem.
Check out this directory: %USERPROFILE%\.vscode\extensions\esbenp.prettier-vscode-9.9.0\node_modules\prettier\
Open up index.js
, go to function getPreferredQuote
and comment out or delete the following:
if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
result = numPreferredQuotes > numAlternateQuotes ? alternate : preferred;
}
Now your result
will always be preferred
.
(save + restart)
Upvotes: 0
Reputation: 524
Try, creating file .prettierrc
at root level, i.e sibling to package.json, with property singleQuote
set to true as below:
{
"singleQuote": true
}
Upvotes: -2
Reputation: 19
This is as intended. From https://github.com/prettier/prettier/tree/21733e441dc01f7d85b483edee92b7e7507bfd9a#quotes:
Upvotes: 1