Prettier-vscode: indent size is 2 instead of 4 - Failed to resolve config - No local configuration detected

Created on 20 Nov 2019  路  6Comments  路  Source: prettier/prettier-vscode

Summary

My .prettierrc file is not used to format my files.

Expected result

I expect the file to be formatted with 4 spaces

Actual result

The file gets formatted with 2 spaces

### Screenshot
image

VS Code Version: 1.40.1

Prettier & Prettier Plugin Version:
"prettier": "^1.19.1"
"prettier plugin": [3.8.0]

OS and version:
Windows 10 Pro

.editorconfig

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

.prettierrc

{
    "bracketSpacing": true,
    "bracesSpacing": true,
    "jsxBracketSameLine": true,
    "jsxSingleQuote": true,
    "noSemi": true,
    "printWidth": 120,
    "singleQuote": true,
    "tabWidth": 4,
    "trailingComma": "none",
    "useTabs": false
}

.prettierignore

.vscode/*
package.json
yarn.lock

I tried to delete the .prettierignore file, but I keep seeing this log :

Resolved ignore file to c:\repos\project\.prettierignore

I restared VSCode many times, and everytime I use the format commande I see this message. :angry:

settings.json

{
  "editor.tabSize": 4,
  "editor.detectIndentation": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Prettier Log Output

[INFO - 3:14:35 PM] Formatting c:\repos\project\Components\Order.jsx.
[INFO - 3:14:35 PM] Loaded module '[email protected]' from 'c:\repos\project\node_modules\prettier\index.js'.
[INFO - 3:14:35 PM] Resolved ignore file to c:\repos\project\.prettierignore.
[INFO - 3:14:35 PM] File Info:
{
  "ignored": false,
  "inferredParser": "babel"
}
[ERROR - 3:14:35 PM] Failed to resolve config for c:\repos\project\Components\Order.jsx. Falling back to the default config settings.
[INFO - 3:14:35 PM] No local configuration detected, using VS Code configuration.
[INFO - 3:14:35 PM] Prettier Options:
{
  "arrowParens": "avoid",
  "bracketSpacing": true,
  "endOfLine": "auto",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "none",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "c:\\repos\\project\\Components\\Order.jsx",
  "parser": "babel"
}
[INFO - 3:14:35 PM] Formatting completed in 31.861999ms.
bug locked

Most helpful comment

I think I have somewhat figured out what is going on here. It appears to be a text encoding issue with the .prettierrc file. I added some additional logging in v3.11.0 (just released). When using the provided repo I noticed the following error:

image

The immediate fix is to change the encoding of the .prettierrc file to utf8. I will try to see if there is a better fix later, but this should unblock you at the moment.

All 6 comments

Resolved ignore file to c:\repos\project.prettierignore
This doesn't mean anything, it just means that is the location that it looks for the ignore file. If the file is not there, then it isn't used.

Is your .prettierrc file located at c:\repos\project\.prettierrc? What about your .editorconfig, where is that located?

This extension uses prettier to resolve configuration files which is:

"The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found."

It sounds like your configuration files are not in the same tree as the file being formatted so they wouldnt be discovered.

@ntotten my .prettierrc is located at the root folder c:\repos\project\
I also tried to move .prettierrc at the same level of my components c:\repos\project\Components\

But I still get that error Failed to resolve config for c:\repos\project\Components\Order.jsx. Falling back to the default config settings.

To be sure that EditorConfig is not causing any conflicts. I removed .editorconfig from my root folder but It still doesn't work.

EDIT 1:
I have the same problem with VSCode Insider v1.41.0 with only Prettier extension installed

EDIT 2:
I have created a sample repo https://github.com/wassim-azirar/prettier-problem

EDIT 3:
With WebStorm everything works fine. I get my 4 spaces instead of 2.

Seeing the same problem as @wassim-azirar
I have .prettierrc.yaml in repository root but settings inside that are not being respected when vs code runs prettier.

VS Code

Version: 1.40.1
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:47:44.719Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 18.6.0

Prettier Extension 3.9.0

I think I have somewhat figured out what is going on here. It appears to be a text encoding issue with the .prettierrc file. I added some additional logging in v3.11.0 (just released). When using the provided repo I noticed the following error:

image

The immediate fix is to change the encoding of the .prettierrc file to utf8. I will try to see if there is a better fix later, but this should unblock you at the moment.

Closing as this issue seems to be resolved.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings