Bug 353546 - [formatter] JavaScript formatter indents the whole object
Summary: [formatter] JavaScript formatter indents the whole object
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-02 04:49 EDT by Victor Homyakov CLA
Modified: 2020-04-30 10:36 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Homyakov CLA 2011-08-02 04:49:25 EDT
Overview:
When long line of code is present in object, JavaScript formatter indents the whole object instead of wrapping of single long line. The long line stays unwrapped.

Steps to Reproduce:
1. In Eclipse go to menu Window -> Preferences. Select JavaScript -> Code Style -> Formatter. Set Active profile to Java Conventions [built-in] (for this particular example, but the same behavior is preserved with all profiles).
2. Make JavaScript file with following content:
--- start of code
var A = Class.create({
    initialize : function() {
        this.afterCancel = Prototype.emptyFunction;
    }
});

var B = Class.create({
    initialize : function() {
        this.afterOpen = this.afterSave = this.afterDelete = this.afterCancel = Prototype.emptyFunction;
    }
});
--- end of code
Note the long line of code (104 chars).
3. Format the source (Ctrl-Shift-F).

Actual Results:
--- start of code
var A = Class.create({
    initialize : function() {
	this.afterCancel = Prototype.emptyFunction;
    }
});

var B = Class
        .create({
            initialize : function() {
                this.afterOpen = this.afterSave = this.afterDelete = this.afterCancel = Prototype.emptyFunction;
            }
        });
--- end of code
Note that contents of object was indented by extra 2 levels, but the long line of code is still unwrapped and even longer than before (112 chars).

Expected Results:
Example should stay unchanged, or at least the single long line should be wrapped somehow. Indentation in other regions of code should not change.

Build Date & Platform:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Release
Build id: 20110615-0604
Comment 1 Jamie Talbot CLA 2011-12-16 17:29:30 EST
Confirmed.  The newline between 'Class' and '.create' for var B is particularly annoying.


org.eclipse.wst.jsdt.feature (1.3.1.v201108102009-7F78FXRFBBoPbXRPcHfz-uy) "Eclipse JavaScript Development Tools"
Comment 2 Wang Jialiang CLA 2013-03-07 19:22:13 EST
This bug has been there for almost five years now and reported many times.
It's sad to see it still hasn't got fixed.

There are some workaround for this issue.
Break up the long lines and go for shorter variable names.

Hope this could be fixed soon, if ever :(
Comment 3 Cody Matal CLA 2020-04-30 10:36:17 EDT
It's absolutely insane that this bug exists almost nine years later.  Has it ever been looked at?