PHP-CS-Fixer: Regression: braces fixer removes empty lines

Prior to the new braces fixer implementation, the following was left alone:

class Foo
{

    protected $bar;

With the new implementation, this is now “fixed” to:

class Foo
{
    protected $bar

Neither PSR-1 nor PSR-2 disallow the original. While the change may lead to greater consistency, unfortunately, it also means that code that was previously passing via php-cs-fixer is now flagged as invalid. Considering that the original is not disallowed by PSR-1/PSR-2, I recommend that the new behavior be an opt-in flag separate from those fixers.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 33 (33 by maintainers)

Commits related to this issue

Most upvoted comments

I feel like we are running in circles here.

I will go back from where this all started:

Current BracesFixer is a PSR2 fixer with the folloowing description:

'The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.';

PSR2 specifies: The closing brace MUST be on the next line after the body

This goes for classes, method declarations, control structures. The BracesFixer fixes these accordingly PSR2

PSR2 however does not have any rule for blank lines after opening braces, only about its placements on newline or not. This issue was opened as the BracesFixer incorrectly removes blanklines after opening braces. BracesFixer should be changed to not remove them, as users would expect from fixers of PSR2 level to not change valid code.

As many people might still want the behavior to have the newlines after opening braces removed i suggested to make a separate fixer for that at contrib/symfony level.