How to format JavaScript Code?

Hi to all,
I just move to IntelliJ Ultimate 11.1 from VS2010(Visual Studio 2010).
I'm a JavaScript developer and what I'm really mising in IntelliJ or at least I dodn't found how to do it is:
In VS2010 when you write the following code:
function a(a){var a=1; if(a===1){a=2;}else {a=3}return a;}
and you close every a block of code with '}'
it will reformat the piece of code automatically with indents and you will get:
function a(a) {
     var a=1;
     if(a===1) {
          a=2;
     } else {
          a=3;
     }
return a;
}
If there is a plug-in or a way of do it this in IntelliJ?
Thanks in advanced

3 comments
Comment actions Permalink

Hi Omer,

You can select the target text and run 'Reformat' action. It will change the text according to your code style settings.

Denis

0
Comment actions Permalink

Hi, thanks for your response,
this is what I'm currently doing, I was guessing if this can be done automatically like in VS2010, that is done every time I close a block, and not to mark the part of the code or all the file and run the 'Reformat' action.
Thanks

0
Comment actions Permalink

No, the IDE doens't offer such an ability.

But why do you code in a single line? You can just type <enter> whenever necessary on typing, the IDE will automatically position caret with the right indent on a new line.

Denis

0

Please sign in to leave a comment.