Anyone else come across Prettier formatting code with Double quotes instead of Single even though you
explicitly set it to replace with single in the preferences?
Here is a pic:
After a recent update to VSCode I started getting this issue and it is driving me crazy.
Any ideas as to how to fix this. Am I wrong that the Prettier: Single Quote in fact does not format with single quotes instead of double?
Thanks.
Try to create file .prettierrc at package.json level with property singleQuote set to true as below:
{
"singleQuote": true
}
Related
I'm having an issue with VSCode formatting on Save.
While some of the settings work as expected I can't figure out why quotes don't work.
(I guess it could be a limitation)
I have this settings
"javascript.format.semicolons": "insert",
"javascript.preferences.quoteStyle": "double",
Semicolons work as expected, but not the quotes. I notice this is a "preferences" so I'm guessing it's not applied when formatting.
Can I get formatting without an extension like Prettier? And what is the "preference" used for if not formatting in this case?
I'm using prettier to format my Vue files, but can't find to seem a setting that puts props/attributes of html elements to new lines.
I'd like to make sure that my code is always formatted as it is for v-text-fieldin a yellow frame, rather than below. I set Prose Wrap to "never", but I guess that was not it. Any help appreciated!
You can set the setting of Print Width to higher value.
That's what Prettier does: breaks lines if they get too long. It doesn't make sense to use Prettier if you don't need its line-breaking behavior as this behavior and Prettier are one and the same.
Using Prettier extension in VSCode.
Have the Single Quote set to single.
format onSave is set to true.
Still...
When I hit save, single quotes are converted to double..
WHY? WHY? WHY? WHY?
In addition...
I've set eslint to use single quotes
I've even deleted the eslint extension from VSCode.
// in .eslint file
"quotes": [2, "single", { "avoidEscape": true }],
Still...
When I hit save, single quotes are converted to double..
WHYYYY?
I've traced the source of the problem.
It appears there are levels of configuration that will be checked when VSCode attempts to reformat the text when format on save is checked.
Prettier extension config
.eslintrc
.editorconfig
I'm still not sure in what order they run in, thus who has the final say.
But in my case, a VERY basic .editorconfig was the problem. Deleting this file fixed it.
# EditorConfig https://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
In the file ^^ there is no mention of spacing prefs at all. So I'm assuming there are some defaults to double quotes.
I have my Prettier extension set to make my code prettier on save. It works amazing 99% of the time...
However:
If I type
If (x = 14) {};
my prettier extension in VsCode will change it to
if ((x=14)) {};
which will cause nothing to work. I have tried everything to fix this. Prettier is great, but this is so annoying, please help ...
It looks suspicious to me that you use single equal sign in the if statement. Are you sure you want to assign a value? Not sure why prettier uses double brackets though. It may be to highlight the unusual.
for example, when I write
foo( bar ){}
it will be formatted to
foo(bar){}
how do I make it keep the 2 spaces?
Edit:
This is a different question from How to change indentation in Visual Studio Code?
Putting
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true
in the settings json solved the problem.