Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353546

Summary: [formatter] JavaScript formatter indents the whole object
Product: [WebTools] JSDT Reporter: Victor Homyakov <vkhomyackov>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: NEW --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cmatal, code, starwhisperer
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

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?