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
- Update BracesFixer Do not remove PSR2 allowed blanklines after class opening brace, fixes #567 — committed to ceeram/PHP-CS-Fixer by ceeram 10 years ago
- bug #874 BracesFixer - fix bug of removing empty lines after class' opening { (ceeram) This PR was squashed before being merged into the 1.4 branch (closes #874). Discussion ---------- BracesFixer ... — committed to PHP-CS-Fixer/PHP-CS-Fixer by keradus 10 years ago
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.