Format on save is inconsistent as sometimes it destroys the format rather than clean it up

I'm new to Jetbrains software and have always had issues with formatting on save. I don't know what sets it off, but sometimes it will save nested objects in a completely unreadable format and I don't know why.  Here is a recent example:

It's completely valid syntax.  It can be really frusturating when this happens because there is no way for me to undo it, I have to go through and format correctly manually. After I fix it manually and then hit save it will stay in its' clean state:

I don't know what sets it off.  Is this normal/a known issue, I don't know if Jetbrains format on save is just subpar or something?

5 comments
Comment actions Permalink

Formatting can be broken if you try to format code with syntax errors - as formatting is based on the syntax tree built by the syntax analyzer, any syntax error can result in a mess

What tool is used for formatting, BTW? Is it Prettier or the IDE own formatter?

0
Comment actions Permalink

It is the default IDE formatter. It is valid syntax, my react app would still compile. It seems like it can format in different ways depending on how it is originally. I thought it would just always format the same way for consistency

0
Comment actions Permalink

Formatting results may depend on original state, as some settings (existing line breaks, etc.) are preserved by default

0
Comment actions Permalink

Ok.  Is there an easy way to set it up so it is independent of the original state and saves to the exact same format everytime? 

0
Comment actions Permalink

Try disabling all Keep when reformatting options everywhere, make sure that all punctuation options are set to Always

0

Please sign in to leave a comment.