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 258462 - Blank Lines 0 setting is being ignored
Summary: Blank Lines 0 setting is being ignored
Status: RESOLVED WORKSFORME
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-21 11:35 UTC by adam_felix_fps
Modified: 2016-08-17 08:42 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description adam_felix_fps 2016-03-21 11:35:29 UTC
When trying to adhere to PSR2 I have the following settings for Blank Lines: Before Class: 1,
After Class Header: 0,
Before Class End: 0,
After Class 1.

This should result in a class being formatted as:

class Foo()
{
    protected $fakeItem;
}

However what I get is:

class Foo()
{

    protected $fakeItem;

}

The extra blank lines cause the file to fail PSR2.

It is as if the 0 is not recognized and therefore defaulting to 1.  If I set it to 2 I correctly get 2 blank lines so I don;t think it is being overriden by something else.
Comment 1 adam_felix_fps 2016-03-21 11:38:02 UTC
Looking again I think this is due to After function being set as 1.  Class End should override after function as you are setting it for the end of the class.  If you set function end to 0 you won't get a space between multiple functions.
Comment 2 junichi11 2016-03-27 05:28:12 UTC
Perhaps, you have the following settings:

- Before Fields: 1
- After Fields: 1

Please try changing them to 0.

BTW, I don't think that it is P2.

Thanks.
Comment 3 adam_felix_fps 2016-03-29 07:53:11 UTC
LOL Priority would depend on whether or not your code has to adhere to PSR2 I guess :)

I have tried your suggestion but when formatting and there are no fields I still get a blank line added.  I looked at the source code for the formatter and there seems to be some kind of exception to the rule which is causing this to happen.

See below from TokenFormatter.java starting at line 617 in my version of the source:

case WHITESPACE_AFTER_CLASS_LEFT_BRACE:
    indentRule = true;
    newLines = docOptions.blankLinesAfterClassHeader + 1 > newLines ? docOptions.blankLinesAfterClassHeader + 1 : newLines;
    countSpaces = indent;
    break;

There is the bit that checks to see if the set option + 1 is greater than new lines and if it is then an extra line is added.  When the class only has functions and no fields then this extra line is always inserted.  When there are fields it is not.  I think it should always insert the number of lines that the user has set if they are trying to adhere to PSR2.
Comment 4 Tomas Mysik 2016-08-17 08:42:35 UTC
(In reply to junichi11 from comment #2)
> - Before Fields: 1
> - After Fields: 1
> 
> Please try changing them to 0.

With this settings, it works for me without any problem.

Thanks for reporting.

Product Version: NetBeans IDE Dev (Build 20160817-5dcbb81aefbb)
Java: 1.8.0_101; Java HotSpot(TM) 64-Bit Server VM 25.101-b13
Runtime: Java(TM) SE Runtime Environment 1.8.0_101-b13
System: Linux version 4.4.0-34-generic running on amd64; UTF-8; cs_CZ (nb)