'Getting format on save to work with a default formatter

I am trying to set a default formatter for a specific workspace to Prettier and make format on save work nicely with each other. I tried this as follows:

enter image description here enter image description here

(format on save is also enabled in the User settings)

For some reason, this is not working for me. If I manually run the format command via VS Code's command pallet, it formats using Prettier just fine.

Is there something I got wrong or another setting that needs configuring?



Solution 1:[1]

Check if in your settings.json file, { "editor.formatOnSave": false } is set to False, if yes, set it to true, I don't know why, but this value could still be set to false, even if both your above settings are turned on.

check:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "prettier.configPath": "./personal.yml"
}

if not, update the editor.defaultForamatter here to the shown value

Also, in your Editor:Default Formatter to None. Note that this is an alternative method (if above doesn't work)

Scroll down to check if formatter if enabled(checked) for all your languages

If this too doesn't work, one can always try rolling to a different version. Or as a last resort, you can try uninstalling and installing vscode

Solution 2:[2]

Follow these steps:

  1. CTRL + SHIFT + P
  2. Format Document (in pop-up bar)
  3. Select Format Document
  4. Select Configure Default Formatter...
  5. Select Prettier - Code formatter

Done!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Strange
Solution 2 Anye