Reputation: 543
I am working on a React project using Visual Studio Code. When I press Ctrl+S in Visual Studio Code to save the file, it removes all the JavaScript formatting or scatters all the code in the file.
Any help would be appreciated.
Upvotes: 12
Views: 47547
Reputation: 595
To automatically format the file on save, In Visual Studio Code, press
Control + Shift + P
or Command + Shift + P (Mac)
to open the command palette and type settings
, select Preferences: Open User Settings
option. Search for the format on save
setting and check the checkbox.
Upvotes: -1
Reputation: 39
In my case it was due to enabled Default HTML formatter:
Push Ctrl + >, then Extentions > HTML:
Upvotes: 0
Reputation: 115
To expand on Tuxedo Joe's answer, your issue might be with your formatter extension:
Check if "Format On Save" is disabled
Disable formatting on save in formatter.json
:
formatter.json
set "onSave" to falseformatter.json
Upvotes: 8
Reputation: 11
First of all, check whether 'Format on Safe' is enabled or not.
If you've got it disabled, check the format text. It's probably that you've got javascript or html format. Change it to 'react' or 'javascript react' format.
Upvotes: 1
Reputation: 341
select language mode by clicking on your bottom right hand from javascript/html to react
Upvotes: 2
Reputation: 156
You disable it "Format On Save"
Upvotes: 14
Reputation: 1897
By default VS Code format on save was enabled, you can disable it by following steps:
javascript.format.enable
to false.Upvotes: 0
Reputation: 962
Try disable extensions for auto-formatting javascript code. Sometimes Beautify, JS-CSS-HTML Formatter can mess things up.
Maybe auto-formatting is on in settings as well. Check File > Preferences > Settings and look at the "User settings"-tab. Look if "editor.formatOnSave" is set to 'true', change that to 'false' in that case.
Hope that helps. If not, please send a list of your activated extensions.
Upvotes: 16