CupawnTae
CupawnTae

Reputation: 14580

IntelliJ 13 won't "keep line breaks" when reformatting javascript

I have the following option enabled:

code-style -> javascript -> keep when reformatting -> line breaks

And yet IntelliJ insists on changing e.g.

var arrrr=[{
},{
}];

to

var arrrr = [
    {
    },
    {
    }
];

I have braces placement set to "end of line" for everything, every other wrapping option says "do not force" or "do not wrap", etc... Am I missing something, or is it a bug?

Alternatively, are there any plugins that would allow me to reformat javascript/json in the first format?

Upvotes: 2

Views: 935

Answers (1)

CupawnTae
CupawnTae

Reputation: 14580

I solved this using the Eclipse Code Formatter plugin - http://plugins.jetbrains.com/plugin/?idea&id=6546

Plugin installation instructions here http://www.jetbrains.com/idea/webhelp/installing-updating-and-uninstalling-repository-plugins.html

Configuration instructions here https://github.com/krasa/EclipseCodeFormatter#instructions

Summary:

  • Open Eclipse (yes you have to have Eclipse installed unfortunately, unless you can can a config file you like from somewhere)
  • Set the javascript formatter options you want in Eclipse - the defaults are pretty much what I was looking for in the question
  • Export the formatter settings to an xml file (you need to change the profile name if you want to export the default settings)
  • Install the Eclipse Code Formatter plugin in Intellij
  • IntelliJ -> Settings -> Eclipse Code Formatter
    • Enable the plugin
    • Set Eclipse Javascript Formatter config file -> your exported xml

Now IntelliJ will use the eclipse formatter instead of its own.

Very useful too if you're working with a team that are using eclipse, so you can all use the same formatting options.

Upvotes: 2

Related Questions