Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-formatting Code in WebStorm 6 Akin to Sublime Text's Alignment Plugin

I'm a long time Sublime Text user but I recently downloaded WebStorm 6 (6.0.2) and I really like it but I haven't been able to find a plugin that matches Sublime's Alignment Plugin that re-formats my code which I use extensively (yes, I'm slightly fanatical about my code formatting).

For example, in Sublime I can take this code block:

user : {
  name    : "Bruce Wayne",
  alias   : "Batman",
  favColour : "black",
  dob : "unknown"
}

And after using the Alignment keyboard shortcut it becomes:

user : {
  name      : "Bruce Wayne",
  alias     : "Batman",
  favColour : "black",
  dob       : "unknown"
}

I've looked into the "Reformat Code" option (Code > Reformat Code...) but in this case it doesn't do anything to the formatting as Webstorm believes that it's already correctly formatted, which is in fact entirely correct, just not to my personal standards.

So my question is: is there a (fairly) easy way to accomplish this or is there a plugin that you know of available for WebStorm that offers the same/similar functionality?

Thanks in advance!

like image 699
NotJustClarkKent Avatar asked Jan 14 '23 01:01

NotJustClarkKent


1 Answers

Code formatting settings are configured at Settings (Preferences on Mac) | Code Style | JavaScript. The Reformat Code is just a command that reformats selection/file accordingly to those rules.

The Code Style for JavaScript has an option to make such alignment:

  • "Spaces" tab | Other | Before property name-value separator ':' -- ticked
  • "Other" tab | Align object properties = On colon
like image 60
LazyOne Avatar answered Jan 23 '23 15:01

LazyOne