Repository navigation
[printer] Keep blank lines between statements when a node list is emptied - #8886
Merged
TomasVotruba merged 2 commits intoOct 29, 2026
Merged
Conversation
TomasVotruba
marked this pull request as draft
October 29, 2026 08:27
TomasVotruba
marked this pull request as ready for review
October 29, 2026 08:37
TomasVotruba
deleted the
preserve-blank-lines-on-emptied-implements-list
branch
October 29, 2026 08:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a rule empties a node list - most commonly removing the last
implementsinterface from a class - php-parser's format-preserving printer gives up on that node (PrettyPrinterAbstract::pArray()has// TODO: Support removing single node) and falls back to a full reprint of the parent. That full reprint drops the blank lines between the class statements.Example - removing the interface collapses the spacing between methods:
became:
This surfaced in
EventSubscriberToAttributeRector(rector-symfony), which dropsEventSubscriberInterfacewhile converting to#[AsEventListener].Fix
BetterStandardPrinter::pArray()now handles the "whole list removed" case php-parser bails on: it cuts just the emptied clause (keyword + types) from the original tokens and keeps the rest format-preserved, so the surrounding statements keep their original blank lines. Covered keywords:implements(class, enum) and interfaceextends.Guards: only fires when the new list is empty and the original was not, the keyword token is actually present, and no PHP tag sits in the removed range.
Test
testKeepBlankLinesBetweenMethodsWhenImplementsRemovedparses a class, emptiesimplements, prints format-preserving and asserts the blank line between methods survives. It fails onmainand passes with this change.