18

In VSCode, whenever I save a file, Prettier changes all single quotes to double quotes. I want to keep this behaviour for SCSS and CSS files, but want to change it for JavaScript and JSON files.

I am aware of the setting "prettier.singleQuote": true, but this will change double quotes to single quotes in all file types.

How can I activate single quote only for JavaScript and JSON files and keep double quote for SCSS and CSS files?

Gama11
  • 31,714
  • 9
  • 78
  • 100
user1941537
  • 6,097
  • 14
  • 52
  • 99
  • Did the accepted answer work for you with JSON files? Single quotes [are invalid when surrounding property names or string values in JSON](https://www.json.org/json-en.html) and prettier seems to [appropriately] ignore `singleQuote: true` there for me. – ruffin Jul 26 '23 at 17:03

1 Answers1

53

Use a Prettier configuration file in your project folder: .prettierrc

Inside your config file use Prettier overrides: https://prettier.io/docs/en/configuration.html#configuration-overrides

So in your case this example config should work (.prettierrc):

{
    "singleQuote": true,
    "overrides": [
        {
            "files": ["**/*.css", "**/*.scss", "**/*.html"],
            "options": {
                "singleQuote": false
            }
        }
    ]
}
Siddi
  • 984
  • 10
  • 19
  • 1
    I see here you are ignoring ALL html files, what about a situation where I want – WillD Jun 08 '21 at 14:24
  • Thx! But why it's necessary to do this, when I already configured this in my vs code settings (which wasn't working so I ended up googling it).. – Tarabass Jun 18 '23 at 18:25