Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier single quote for JavaScript and JSON, double quote for HTML, Sass and CSS

Tags:

prettier

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?

like image 817
user1941537 Avatar asked Mar 30 '19 11:03

user1941537


People also ask

Can you use single quotes in CSS?

There is no difference between single or double quotes. You can simply use single quotes or double quotes, that is simply up to you, but my recommendation is to use double quotes. Especially when you will want to add some JS, you will find it very useful.


1 Answers

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
            }
        }
    ]
}
like image 70
Siddi Avatar answered Jan 02 '23 02:01

Siddi