Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 419931 - Array initializer auto-formatting is a hideous, broken nightmare
Summary: Array initializer auto-formatting is a hideous, broken nightmare
Status: CLOSED DUPLICATE of bug 356606
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Patrik Suzzi CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard: greatfix_candidate RHT
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-20 12:23 EDT by Jon Rimmer CLA
Modified: 2016-08-23 13:41 EDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Rimmer CLA 2013-10-20 12:23:33 EDT
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.
Comment 1 Szczepan Holyszewski CLA 2015-03-22 17:27:08 EDT
Will this EVER be fixed?
Comment 2 Nitin Dahyabhai CLA 2016-07-18 10:00:09 EDT
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.
Comment 3 Gorkem Ercan CLA 2016-08-23 13:41:04 EDT

*** This bug has been marked as a duplicate of bug 356606 ***