GN.
GN.

Reputation: 9909

Prettier VSCode. Single Quotes set, yet ALWAYS changes it to double

  1. Using Prettier extension in VSCode.

  2. Have the Single Quote set to single.

  3. format onSave is set to true.

Still... When I hit save, single quotes are converted to double..

WHY? WHY? WHY? WHY?


In addition...

  1. I've set eslint to use single quotes
  2. 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?

Upvotes: 4

Views: 5388

Answers (2)

pepperslhcb
pepperslhcb

Reputation: 31

I have the same problem. make sure if prettier is using any other config that could override it's own settings in VSCode. most likely to be .editorconfig

there's two options

  1. still use .editorconfig

Add this code in .editorconfig

quote_type = single
  1. stop using .editorconfig

In .vscode/settings.json, add this code.

"prettier.useEditorConfig": false, // tell prettier to don't use .editorconfig

"prettier.singleQuote": true, // force single quote

Upvotes: 3

GN.
GN.

Reputation: 9909

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 above there is no mention of spacing prefs at all. So I'm assuming there are some defaults to double quotes.

Upvotes: 6

Related Questions