Fix docblock indentation loss when fixing empty enclosing line#52
Merged
dereuromark merged 2 commits intomasterfrom Apr 10, 2026
Merged
Fix docblock indentation loss when fixing empty enclosing line#52dereuromark merged 2 commits intomasterfrom
dereuromark merged 2 commits intomasterfrom
Conversation
When EmptyEnclosingLine sniff fixed empty lines after class opening brace, it removed all tokens including the newline that should remain. Combined with other fixers (like DisallowTabIndent that converts tabs to spaces), this caused the first content line (typically a docblock) to lose its indentation entirely. The fix explicitly preserves one newline after the opening brace by replacing the first token with a newline character, then removing the remaining tokens up to the content line.
Adds test cases to verify that the EmptyEnclosingLine sniff correctly preserves indentation when removing empty lines after class opening braces, particularly when using tabs.
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.
Summary
EmptyEnclosingLineSniffcaused docblock indentation to be lost when combined with other fixersProblem
When processing a file with tabs and an empty line after a class opening brace, running phpcbf with the full PhpCollective ruleset caused the first content (typically a docblock) to lose its indentation entirely.
Input:
Before fix (incorrect):
After fix (correct):
Root Cause
The
EmptyEnclosingLineSniffremoved all tokens between the opening brace and the first content line, including the newline that should remain. When combined withGeneric.WhiteSpace.DisallowTabIndent(which converts tabs to spaces), the fixer loop interactions caused the indentation token to be lost.Solution
The fix explicitly preserves one newline after the opening brace by:
All existing tests pass.