Community
Participate
Working Groups
If you are writing an array initializer in JavaScript, you most likely want to it to look like this: var myArray = [ item1, item2, item3, ... ]; However, no matter how you configure Eclipse to format array initializers, it ignores it all and instead tries to make you kill yourself with frustration. Actually *typing* an array initializer goes like this, cursor position indicated by _ 1. You type the following: var myArray = [_ 2. Eclipse inserts a closing paren: var myArray = [_] 3. You press enter, expecting to a get a newline, but instead Eclipse interprets it as "move the cursor to the end of the line: var myArray = []_ 4. You left-arrow the cursor back a position, and press enter again. This time, Eclipse does insert a newline. But it auto-indents as follows: var myArray = [ _] Rather than following the same, sane behaviour it provides for object initializers, Eclipse idents the following line to the same column as the opening paren, it idents using spaces, even if you've configured it to use tabs and only tabs for indentation, and it leaves the closing paren on the same line, rather than moving it to the start of the next. Trying to fix the indentation is impossible, because it has used spaces instead of tabs. If you delete the spaces and press tab, it merely re-inserts the spaces and re-indents back to the column of the open paren! It's hard to adequately emphasise what a frustrating, poisonous impression this makes on someone using Eclipse as a tool for JavaScript development. It feels actively user-hostile.
Will this EVER be fixed?
For after-the-fact formatting, in your JavaScript->Code Style->Formatter active profile, for New Lines, make sure that "Insert new line before closing brace of an array initializer" is enabled, and that for Line wrapping's Settings for array initializers, you've chosen to "Wrap all elements, every element on a new line", set the matching Indentation policy to "Indent by one", and are forcing line splitting.
*** This bug has been marked as a duplicate of bug 356606 ***