Unable to set tab width to 4 in prettier

javanoob picture javanoob · Oct 27, 2019 · Viewed 9.5k times · Source

I installed prettier extension for vscode and configured tab width as 4 spaces but it still indents new lines with 2 spaces. Anything I am doing wrong?

enter image description here

Here is the gif showing when I format the file:

enter image description here

EDIT: Contents of .prettierrc file:

{
  "trailingComma": "none",
  "overrides": [
    {
      "files": "**/lwc/**/*.html",
      "options": { "parser": "lwc" }
    },
    {
      "files": "*.{cmp,page,component}",
      "options": { "parser": "html" }
    }
  ]
}

Answer

Akshay Vijay Jain picture Akshay Vijay Jain · Jan 5, 2021

I think it was because, tabWidth:4 was specified in user's settings. while in workspace setting nothing was specified, so it uses default value for workspace i.e. tabWidth:2

as mentioned in comments also adding tabWidth:2 in .prettier.js would fix it!

https://prettier.io/docs/en/options.html#tab-width