Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set up Prettier in VSCode settings to conditionally apply single quotes by file type?

I'm trying to set up Prettier in VSCode settings so that for all file types except JS it will default to double quotes.

I've disabled ESLint to make sure it's not the problem. I've also check Prettier documentation on configuration overrides in JSON. But my settings don't seem to work.

  "prettier": {
    "singleQuote": false,
    "overrides": [
      {
        "files": "*.js",
        "options": {
          "singleQuote": true
        }
      }
    ]
  }

When I save a CSS file I expect to see double quotes and I do. When I save a JS file I expect to see single quotes (when there's no apostrophes used in the string) but it sets double quotes on all strings.

like image 755
Guybrush Threepwood Avatar asked Nov 02 '25 03:11

Guybrush Threepwood


1 Answers

To use single quotes for JavaScript but double quotes for CSS, SCSS, and HTML, in your project root directory, add a .prettierrc file with this JSON:

{
  "singleQuote": true,
  "overrides": [
    {
      "files": ["**/*.css", "**/*.scss", "**/*.html"],
      "options": {
        "singleQuote": false
      }
    }
  ]
}

(Bonus info: The ** is a glob character and represents any number of subfolders within the current folder.)

like image 147
nCardot Avatar answered Nov 03 '25 20:11

nCardot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!