Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Formatting fail on save

Tags:

I've started learning React Native.

I'm using Visual Studio Code as my editor.

I've set up the boiler plate and started the app. But whenever I change a .js file and hit save, VSCode is messing up all the formatting.

Before save After save

I thought I could sort this in the settings.json file but after googling for a while and playing around I can't find the correct setting.

Is this a bug or am I doing something wrong?

Setting file is default one:

enter image description here

UPDATE: I re-installed vscode. Then set up a basic js file with a react native tag and a html tag. I added in:

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

To my settings.json file and the problem still occurs:

pre save post save

The problem is having tags in a js file, I just don't know how to tell vscode to ignore them?

like image 983
Jamadan Avatar asked Mar 31 '17 20:03

Jamadan


People also ask

Why is VSCode not formatting on save?

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 setting and then select Preferences: Open User Settings option. Search for format on save setting and check the checkbox.

How do I fix prettier errors on save?

First check if Prettier works fine. You can try to format a single file using Shift + Cmd + P and Format Document . If this doesn't work then it is most likely an issue with Prettier extension. Disable and Enable Prettier extension from Extensions.


1 Answers

I found out what this was by looking though the extensions. Thanks to @wgj for the hint.

Turns out it was the JS-CSS-HTML formatter. I looked through the instructions and have removed the auto save for now. I'll have to work out the specific settings for this.

It uses js-beautify so if anyone knows the settings I should be looking at would be much appreciated.

enter image description here

like image 161
Jamadan Avatar answered Sep 22 '22 06:09

Jamadan