This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 229334 - Please add support for javascript braces formatting
Summary: Please add support for javascript braces formatting
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.0.1
Hardware: All All
: P2 normal with 7 votes (vote)
Assignee: Roman Svitanic
URL:
Keywords:
: 218843 221866 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-05-03 15:12 UTC by ifishing
Modified: 2015-08-31 20:26 UTC (History)
7 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ifishing 2013-05-03 15:12:29 UTC
In the  Option-->editor-->formatting pane,you will find a  'braces' option  in the Catetory  list if you select Java for language dropdownlist. This enable the user decide how to auto place the brace according to her usual coding style. But if you choose Javascript as the language, you have no choice to decide how to auto formatting your braces. I think there are a lot of developer who are not accustomed to the default brace placing style.
So please add the support for customizing the brace formatting style.
Thanks!
Comment 1 Petr Hejl 2013-07-26 16:03:25 UTC
*** Bug 218843 has been marked as a duplicate of this bug. ***
Comment 2 Petr Hejl 2013-07-26 16:04:25 UTC
*** Bug 221866 has been marked as a duplicate of this bug. ***
Comment 3 ifishing 2013-08-14 02:12:14 UTC
Thanks,petr.
Is there any plan to fix it?
Comment 4 Petr Hejl 2013-08-14 07:13:11 UTC
(In reply to ifishing from comment #3)
> Thanks,petr.
> Is there any plan to fix it?
Not for the 7.4.
Comment 5 Jock924491 2014-03-27 15:41:57 UTC
Hi, I was wondering if there is any plan to work on this in 8?
Comment 6 _ gtzabari 2014-03-27 15:47:47 UTC
Netbeans 8 is already out, but I second Jock's motion: can we please fix this issue already? The misplaced braces are jarring.

Specifically, (as mention in issue #221866) it's not clear to me why you're indenting braces for switch-case statements differently for Javascript than Java. This "default" seems to contradict every single convention I've ever seen, so whether braces are configurable or not this should get fixed.
Comment 7 Jock924491 2014-11-26 17:10:51 UTC
This is still an issue with the JavaScript formatting in 8.02. I've gotta say that the formatting options for JS is extremely lacking in comparison to Eclipse, I have to pull the file into Eclipse just to format it using my company's very specific format. Can we add more formatting support?
Comment 8 _ gtzabari 2014-11-26 17:59:46 UTC
I agree with Jock,

This bug is extremely problematic if you have to adhere to company formatting standards.

Jock, I set Version back to 7.4 because it is meant to denote when the issue was first sighted (not the latest version it is reproducible in).

Please vote for this issue if you want it fixed sooner.
Comment 9 alexboss 2014-12-19 16:21:44 UTC
Indeed, for JavaScript, the formatting options are really poor compared to other languages.

Please add the same level of formatting options as for other languages. 

Thanks a lot, 

Best regards, 

Alexandre 8)
Comment 10 Petr Pisl 2015-01-05 16:54:51 UTC
Adding options and fine tuning formatting is mainly about the time. I have spend probably 6 month with the implementing all the options in PHP formatter. I'm also for the implementation of the bulk of options in JS editor. But I have to admit that there is not so much time now. So we have to be patient.  On the other hand I think that the editor is the most part of the IDE, so I'm also voting for this issue.
Comment 11 Roman Svitanic 2015-01-22 15:42:47 UTC
Changeset: 7675a379a103
Author:    Roman Svitanic <rsvitanic@netbeans.org>
Date:      2015-01-22 16:44
Message:   #229334 - JavaScript Braces Placement formatting
Comment 12 jhcaiced 2015-01-22 15:53:33 UTC
Don't understand why this issue is being marked as RESOLVED/FIXED, the issue is still present in NetBeans 8.0.2

In Options/Editor/Formatting when choosing Language: Javascript, there is still no "Braces" option in the Category selector.

For javascript the only categories available are: Tabs and Indents, Spaces and Wrapping
Comment 13 Lou Dasaro 2015-01-22 17:43:05 UTC
You can see the meaning of "Status" at https://netbeans.org/bugzilla/page.cgi?id=fields.html#bug_status 
Note that the Target Milestone for this issue is Development.

The issue was marked as FIXED because the engineer added/modified code to "Fix" this issue. Normally, such changes will propagate through the NetBeans build system, and in a day (typically) appear in the Development distributions of NetBeans at http://bits.netbeans.org/download/trunk/nightly/latest/

At least, that's the way it usually works. So, if you want to see the result of the change, you'll probably need to download a NetBeans Development distribution in a day or two.
Comment 14 _ gtzabari 2015-01-22 17:55:50 UTC
Roman,

Thank you very much! I'm going to try this out as soon as the next dev build comes out.
Comment 15 Quality Engineering 2015-01-23 04:06:30 UTC
Integrated into 'main-silver', will be available in build *201501230002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/7675a379a103
User: Roman Svitanic <rsvitanic@netbeans.org>
Log: #229334 - JavaScript Braces Placement formatting
Task #229334 - Please add support for javascript braces formatting
Comment 16 _ gtzabari 2015-01-26 02:23:14 UTC
Roman and Lou,

I have one outstanding question about this fix.

Bug #221866 (which is marked duplicate of this issue) complains that code-format is transforming:

switch (error.code)
{
	case error.PERMISSION_DENIED:
	{
			break;
	}
}

to:

switch (error.code)
{
	case error.PERMISSION_DENIED:
		{
			break;
		}
}

With the new Javascript formatting options, I can fix the above by changing "Continuation Indentation" from 2 to 0.

Are you sure that this behavior is appropriate? Does it really make sense for a case block to count as a "continuation"? I thought that a continuation is defined as a single line of code that spans multiple physical lines.

The Javascript formatting options do not match the behavior of the Java formatting options. In the latter, a continuation of 2 does not result in a case block getting indented.

Please let me know what you think.
Comment 17 _ gtzabari 2015-01-26 02:25:40 UTC
In fact, I am pretty sure that this fix did not change the behavior for case statements at all.

Is it possible to reopen bug #221866?
Comment 18 Vladimir Riha 2015-01-26 09:19:47 UTC
_ gtzabari: Could you please attach here full code, where it does not work and perhaps exported IDE settings? I tried it and it works for me just fine, the formatted result is

try {

} catch (error) {
    switch (error.code)
    {
        case error.PERMISSION_DENIED:
        {
            break;
        }
    }
}


Thank you


Product Version: NetBeans IDE Dev (Build 201501260002)
Java: 1.8.0_25; Java HotSpot(TM) Client VM 25.25-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b17
System: Linux version 3.13.0-35-generic running on i386; UTF-8; en_US (nb)
Comment 19 _ gtzabari 2015-01-26 21:16:26 UTC
Vladimir,

My mistake. The problems occurs with Object.defineProperty(), not switch blocks. Given:

Object.defineProperty(this, "uri",
{
	value: uri,
	enumerable: true
});

Code-format converts it to:

Object.defineProperty(this, "uri",
	{
		value: uri,
		enumerable: true
	});

I am expecting it to retain the original formatting. The equivalent Java code (lambda) looks like this:

new Thread(() ->
{
	System.out.println("I am a runnable");
});

If you apply code-format on it, the original indentation will be kept (the block is not treated as a continuation.

Let me know how you want to proceed.
Comment 20 _ gtzabari 2015-01-26 21:44:05 UTC
Vladimir,

Upon further investigation, I don't think any action is required for this issue. The bug I discussed above is already covered by bug #227007 which is still open.
Comment 21 alexboss 2015-02-02 15:15:05 UTC
Thanks a lot for providing these additional features, it is a great improvement.

Nevertheless, are there additional plans to add the following formatting capabilities:

* Alignment: new lines before statements else, elseif, catch, etc.
* Blank lines: introduction blank lines before / after functions, etc.

Thanks a lot, 

Best regards,

Alexandre 8)
Comment 22 Tomasko 2015-06-13 14:47:54 UTC
Still present in Build 201411181905 (8.0.2). No options for configuration of braces for javascript whatsoever.
Comment 23 Roman Svitanic 2015-06-15 07:24:02 UTC
(In reply to Tomasko from comment #22)
> Still present in Build 201411181905 (8.0.2). No options for configuration of
> braces for javascript whatsoever.

Please do not reopen issues until you are sure that issue is not fixed. Look at the field "Target Milestone" which indicates the first version containing the fix. In this case it's "Dev" which means development/nightly builds. The next release containing this feature will be NetBeans 8.1.
Comment 24 mkotsollaris 2015-08-31 20:17:05 UTC
This is indeed very frustrating and unfortunate since 2 years have passed without fixing the issue. At least I hope that you will bother to fix it in the upcoming NB release.
Comment 25 _ gtzabari 2015-08-31 20:19:06 UTC
mkotsollaris,

Did you read the comment above yours before posting this? What version are you saying this is not fixed in?
Comment 26 Vladimir Riha 2015-08-31 20:26:15 UTC
mkotsollaris: This feature will be part of upcoming NetBeans 8.1. You can try daily Dev build from http://bits.netbeans.org/download/trunk/nightly/latest/.

Thank you