prettier-vscode: Can't format user settings.json in vscode

Summary

When the option "editor.defaultFormatter": "esbenp.prettier-vscode" in user settings is set is set, one cannot format the settings.json file itself. Strangely, other json files and the workspace settings file are formatted correctly.

Steps To Reproduce:

Add "editor.defaultFormatter": "esbenp.prettier-vscode" to your user settings.json file and try to format the document after saving.

Expected result

The file should be formatted according to prettier settings like other

Actual result

Following error message is shown in the status bar: Extension 'Prettier Code formatter' cannot format '~/Library/Application Support/Code/User/settings.json'

VS Code Version: 1.37.1

Prettier & Prettier Plugin Version: Prettier v1.18.2 && Plugin Version: 1.9.0

OS and version: macOS 10.14.6

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 16
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Im not really following the conversation around the other vue issues, so please open separate issues with detailed repro steps if needed.

The issue with the settings.json is a problem with VSCode (microsoft/vscode#79038). Essentially, VSCode doesn’t register that file as a regular JSON file and doesn’t call registered formatters. They have said they don’t plan on fixing it because they now have the visual editor. The solution you found of opening the file directly is the workaround.

@ntotten ,

I’m running version 3.5.0. Definitely not fixed.

Attempting to format settings.json causes the following to appear in the VS Code status bar:

Extension ‘Prettier Code Formatter’ cannot format ‘C:\Users\Me\AppData\Roaming\Code\User\settings.json’

I’m running the latest VS Code on the latest Windows 10.

Update: https://github.com/microsoft/vscode/issues/79038#issuecomment-526475411. Summary: Formatting doesn’t work if a folder is open.