IntelliJ does some odd formatting with Javascript code and I am trying to figure out how to get it to stop formatting this way. Whenever I chain jQuery functions together, it over indents the auto created code such as this:

$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
        /* this is where the cursor and closing braces end up */

I want it to look like this:

$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
    /* cursor and closing braces indented normally */

How do I change this?

closed as off-topic by user22815, user40980, durron597, gnat, jwenting May 13 '15 at 9:24

  • This question does not appear to be about software engineering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • the fixes here didn't work for me so I got in touch with jetbrains and they've opened an issue. Please vote for it here: youtrack.jetbrains.com/issue/WEB-15066 – JonnyRaa Feb 4 '15 at 13:35
  • 4
    I am voting to close this question as off-topic because it is about a software tool, however, it is too old to migrate to Stack Overflow. – user22815 May 12 '15 at 22:37

As @intarg mentions, in the comments. You can change File|Settings|Code Style|General and on the Javascript tab set Continuation Indent to 0 for Javascript.

That will get you most of what you want. the problem is that your code is actually all 1 long statement.

function() {
    /* Do some stuff */
}).blur(function() {
    /* this is where the cursor and closing braces end up */

Not sure that there is a relevant option to prevent a line break after focus(

Oh, and be sure that you have the Javascript code sample tab active when you are changing options - otherwise you will not change them for Javascript.

EDIT: Now that I have looked further. The Javascript formatter is coded to add a linebreak in that specific case, there isn't an option for it.

  • This doesnt work for me - I still get the sideways creep as outlined above – JonnyRaa Feb 3 '15 at 10:10

All the settings you need to control code formatting in intellij are in File>Other Settings>Template Settings.

If Javascript is not listed (i.e you've not installed a Javascript plugin), you can define the code formatting under the General tab and then the Other tab. There will be options for controlling indentation and spacing.

  • I think the problem is that it thinks the function from .blur() is a continuation indent. The only way I can stop it from doing this is to set continuation indent to 0, but that makes other code look bad too. Would you happen to know of a way to tell it this is not a continuation indent or is that some internal stuff going on? – intargc Sep 4 '11 at 21:08
  • Have you installed a Javascript plugin into intellij? I know there are a few available. If your not using any of them, the IDE will simply fallback on standard indentation/spacing. You'd ideally use a plugin to make the IDE aware of these constructs. – Desolate Planet Sep 4 '11 at 21:36
  • Have you tried jetbrains? Also, have you tried doing this with Eclipse. I've not touched intellij in a while, but I know Eclipse has got pretty good plugin support and it's easy enough to control indentation, but you really shouldn't have a problem with intellij. – Desolate Planet Sep 4 '11 at 21:39
  • Since the community edition is open source, you can always get the source code, build it and insert breakpoints where it performs the formatting to rule out if there is an internal issue. If it doesn't do what you want, apply a fix and submit a patch to one of the repo owners, if you've got the time and inclination to do so:) – Desolate Planet Sep 4 '11 at 21:47
  • I do have the javascript plugin installed. I'll try jetbrains and see if anyone there has a clue. Thanks. – intargc Sep 4 '11 at 21:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.