Why is vscode formatting my code twice upon saving?
Asked Answered
F

4

7

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.

Fatality answered 28/3, 2021 at 4:38 Comment(1)
Does this answer your question? Can't get correct autoformat on save in Visual Studio Code with ESLint and PrettierYe
F
1

I solved my issue by following the steps outlined in this answer https://mcmap.net/q/382888/-can-39-t-get-correct-autoformat-on-save-in-visual-studio-code-with-eslint-and-prettier

Short answer: I needed:

"editor.formatOnSave": false,
"javascript.format.enable": false
Fatality answered 31/1, 2022 at 18:50 Comment(0)
C
10

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.

Casement answered 24/1, 2022 at 9:30 Comment(1)
Saved couple of hours! thanks mateNape
J
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 :)

Judson answered 12/8, 2021 at 10:56 Comment(1)
I had this issue with stylelint, uninstalling lonefy instantly fixed the problem.Sill
F
1

I solved my issue by following the steps outlined in this answer https://mcmap.net/q/382888/-can-39-t-get-correct-autoformat-on-save-in-visual-studio-code-with-eslint-and-prettier

Short answer: I needed:

"editor.formatOnSave": false,
"javascript.format.enable": false
Fatality answered 31/1, 2022 at 18:50 Comment(0)
S
0

I solved mine by removing this settings:

  "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit",
    "source.fixAll.eslint": "explicit"
  },

Autoimports formatted imports and then eslint reformatted code.

Suburbicarian answered 3/9, 2024 at 20:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.