15

For 2-3 weeks, while I didn't change anything in prettier file, VSC started changing single quotes to double quotes, while it was always single quotes. I tried many options but it keeps changing it. Heres my .prettierrc

{
  "trailingComma": "es5",
  "printWidth": 200,
  "semi": true,
  "singleQuote": true,
  "jsxSingleQuote": true,
  "tabWidth": 2,
  "quoteProps": "as-needed"
}

EDIT: I think, that it is a matter of .tsx files, as prettier has just option for .jsx files but still didn't find a solution.

Dilshod K
  • 2,924
  • 1
  • 13
  • 46
heisenberg7584
  • 563
  • 2
  • 10
  • 30
  • Not really a solution. I was using prettier in the beginning but found it had a lot of quirks with VSCode. I switched to eslint, which works much better. – The Fool Nov 28 '19 at 07:12
  • I have tslint in my project (as it is written in typescript) but when I want to format according to tslint config it doesn't follow those rules from there. – heisenberg7584 Nov 28 '19 at 07:14
  • I think this is your problem. You have more than one tool trying to apply rules. I think you should remove one of them, preferable prettier. And then try to configure the remaining properly. – The Fool Nov 28 '19 at 07:15
  • But tslint will just show error in terminal, just prettier formats files and for now there is just problem with quoting in components files (.tsx) – heisenberg7584 Nov 28 '19 at 07:55
  • I can see you have "jsxSingleQuote": true, . this should solve the problem as long as you are using the latest prettier. I had the same problem but after adding that all the double quotes in my jsx files were turned to double single quotes – Dijiflex Nov 10 '20 at 16:31

6 Answers6

35

In .prettierrc, add:

{
  "singleQuote": true,
  "jsxSingleQuote": true
}
Edmar Miyake
  • 12,047
  • 3
  • 37
  • 38
2

create a .prettierrc file on your root folder and add:

{
  "singleQuote": true
}
Rip3rs
  • 1,284
  • 12
  • 21
1

I have the same issue for a few days. I checked all the settings and they seem to be fine.

At the moment THE ONLY thing that helps is downgrading down to the previous version of Prettier in my case it was version 2.3.0 (I didn't check all the versions between this and the latest but few of them had the same issue)

0

On your User Settings make sure you have the following line:

"prettier.singleQuote": true

You can access the user settings by CTRL+, on windows or CMD+, on mac.

If you're using the settings GUI just search for single quote and check/uncheck the Prettier: Jsx Single quote and Prettier: Single quote

I am L
  • 4,288
  • 6
  • 32
  • 49
0

Best place to read up on this configuration is the website. https://prettier.io/docs/en/configuration.html

If you are using a package.json, create a new key if you dont have a "prettier" key.

"prettier":{
    "singleQuote": true
}

Or you could create a .prettierrc file written in JSON and add the same key pair value.

DSam87
  • 1
0

add tsxSingleQuote: true, in prettierrc.js file

Sushan Yadav
  • 111
  • 2
  • 4