Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop VS Code from totally destroying my code on save?

I've gone through formatting settings and stack overflow posts, I've toggled with a bunch of different settings and can't seem to find an answer to this. Nothing in settings.json seems to matter, maybe it's being overwritten somehow?

My tab spacing is set at 2 spaces and every time I restart my computer, something seems to happen to VS Code where saving a file adds a ton of weird spacing rules and tabs to 4 spaces, as you can see in the gif below that make my code terrible.

I don't want to go back to Atom or Sublime but the way VS Code is working for me right now, I can't use it in a professional context. Would love some help getting this figured out.

Thanks!

(image below is a gif, click it to see the style change on save)

enter image description here

Edit: installed packages in VS Code:

enter image description here

enter image description here

like image 511
Zack Shapiro Avatar asked Apr 23 '19 13:04

Zack Shapiro


People also ask

What is enable auto save option in VS Code?

The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay. For more control over Auto Save , open User or Workspace settings and find the associated settings: files.autoSave : Can have the values: off - to disable auto save.

How do I turn off saved changes in Visual Studio code?

Click the (...) button and then select Undo Last Commit to undo the previous commit. The changes are added to the Staged Changes section.


2 Answers

This comment turns out to have the answer. It happens when you have two settings that shouldn't conflict but do for some reason

"editor.formatOnSave": false,
"javascript.format.enable": false

The solution was to uninstall vscode-JS-CSS-HTML-formatter which you can do by searching for the author, lonefy, in your packages.

like image 52
Zack Shapiro Avatar answered Sep 24 '22 00:09

Zack Shapiro


Its probably Prettier that is doing this.

In your settings.json add these two lines:

"editor.formatOnSave": false,

"prettier.disableLanguages": [
    "jsx",
    "js"
],

Or just uninstall prettier

like image 37
kemotoe Avatar answered Sep 23 '22 00:09

kemotoe