6

I have my editor set to fix all issues upon saving. However, once I saved, it formats the code to fix the issues, then a split second later reverts back to the original unfixed and unformatted code. This started happening after I updated vscode.

Lee
  • 703
  • 6
  • 20
  • Does this answer your question? [Can't get correct autoformat on save in Visual Studio Code with ESLint and Prettier](https://stackoverflow.com/questions/52102705/cant-get-correct-autoformat-on-save-in-visual-studio-code-with-eslint-and-prett) – Quentin Dec 21 '22 at 11:40

3 Answers3

9

Not saying this will be your case, but worth checking:

  1. Make sure this setting is false: "editor.formatOnSave": false
  2. Add this to the settings.json file :
"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },

If you don't use ESLint / Prettier installed, then do the opposite, meaning just make sure that formatOnSave is set to true and you don't have other formatters enabled.

Jonathan Perry
  • 2,953
  • 2
  • 44
  • 51
2

I had the same problem and it really killed me as I uninstalled prettier and eslint, reset the rules and everything...

Until I saw I had that lonefy.vscode-js-css-html-formatter package, which is silent in the settings but still forces its own opinionated formatting rules. Uninstalling it made the trick :)

Francois
  • 21
  • 2
0

I solved my issue by following the steps outlined in this answer https://stackoverflow.com/a/52259752/9491881

Short answer: I needed:

"editor.formatOnSave": false,
"javascript.format.enable": false
T J
  • 42,762
  • 13
  • 83
  • 138
Lee
  • 703
  • 6
  • 20