Prettier VSCode. Single Quotes set, yet ALWAYS changes it to double - visual-studio-code

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.

Related

Always use double quotes in schema.prisma with Prettier in VSCode

I use prettier to save all quotes as single quotes in my JS and TS files.
However, single quotes are not valid in schema.prisma. Can I specify within Prettier to treat specific file extensions differently?
I have the "Prisma" extension in VS Code as well and tried to enable
"editor.formatOnSave": true
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
},
But it's not changing the single quotes in my schema.prisma file on save. What config and/or extensions do I need to achieve this behavior?

How can I selectively trim trailing whitespace in VSCode?

I generally have the Trim Trailing Whitespace setting turned on in VSCode because I want that behaviour for code files.
However, I have a folder of text resources (.txt files) that I would like to exclude from this rule. Some of the text files need trailing whitespace on the lines.
Is it possible to selectively turn this rule on/off based on file path or file extension?
I've tried having a .vscode/settings.json file at the root of my workspace turning the feature on, and another in the folder containing the text resources to turn it off and that doesn't work.
Is there an extension that enables this? I looked but wasn't able to find one.
In settings.json, insert:
"[plaintext]": {
"files.trimTrailingWhitespace": false
}

Prettier formatting with double quotes

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
}

VS Code automatically deleting internal spaces on save

I'm trying to make some statements visually line-up on the equal signs (per company style), which requires me putting extra spaces inside the line.
However, when I press save, VS Code deletes the spaces: even though I have all extensions off, and have it set to show all whitespace.
clip of problem, jump is on save
Any clue what might be causing this? I've tried restarting, toggling all the whitespace settings, disabling all extensions; no luck.
ctrl+comma
add line:
"editor.formatOnSave": false
You can also exclude some file types from format on save if you don't want to turn format on save off:
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
}

How do you remove trailing spaces in all files except Markdown?

In Visual Studio Code the setting
"files.trimTrailingWhitespace": true
removes trailing white space when files are saved, or Shift + Alt + F is used to format a file, but this breaks Markdown formatting.
How do you selectively turn off white space trimming for Markdown?
Add this line to your settings.json file.
"[markdown]": {
"files.trimTrailingWhitespace": false
}
You can use EditorConfig by adding .editorconfig at the root of your project:
[!markdown]
trim_trailing_whitespace: false
Or as GollyJer suggested, add this code snippet in the settings.json file:
"[markdown]": {
"files.trimTrailingWhitespace": false
}
You can now (VSCode 1.68, May 2022) do this through the Settings GUI instead of directly your settings.json.
Settings editor improvements
The Settings editor now shows a default value override indicator for language-specific settings.
As a note, one can view language-specific settings by adding a language filter in the Settings editor search bar, and one can add such a filter either by typing it out explicitly, or by clicking the filter button on the right of the search bar, and selecting the "Language" option.
When the default value override indicator shows up, it indicates that the default value of the language-specific setting has been overridden by an extension. The indicator also indicates which extension overrode the default value.
(Theme Light Pink)
This example above is for line wrapping, but you can adapt it to reference trim_trailing_whitespace.
Do Ctrl-K s. This will "Save without formatting", which also means, without trimming trailing whitespace in the file you're editing
Solution
Add or update .editorconfig in root of your project and add the 2 following lines to prevent trimming on whitespace in VScode on matching file extension's
Update .editorconfig with following
[*.md]
trim_trailing_whitespace = false
[*.mdx]
trim_trailing_whitespace = false