Skip to content

Fix DocComment fixer emitting tab indentation - #79

Merged
dereuromark merged 1 commit into
masterfrom
doccomment-tab-indentation
Aug 6, 2026
Merged

Fix DocComment fixer emitting tab indentation#79
dereuromark merged 1 commit into
masterfrom
doccomment-tab-indentation

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Two fixes in DocCommentSniff built indentation like this:

$indentation = $tokens[$commentStart]['column'] - 1;
$indentation = str_repeat("\t", $indentation);

That is wrong in two ways at once.

It emits tabs the standard forbids. The ruleset enables Generic.WhiteSpace.DisallowTabIndent, so running phpcbf produced indentation that phpcs then reports:

 7 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
   |       |     (Generic.WhiteSpace.DisallowTabIndent.TabsUsed)

It uses a column offset as a repeat count. A doc block indented one level with four spaces sits at column 5, so it emitted four tabs - four levels of indentation for a one-level block.

On a normal space-indented file, /** Summary. @param string $a */ came out as:

    /** Summary. @param string $a
				 */

Both sites now use getIndentationWhitespace(), the helper already used for this in DocBlockTagGrouping, which reads the line's actual leading whitespace:

    /** Summary. @param string $a
     */

The DocComment fixture from #73 recorded the tab output as current behavior; it now records the file's own indentation. Regenerated from the fixer rather than hand-edited.

Two fixes built their indentation as str_repeat("\t", column - 1). That is
wrong twice over: the standard enables Generic.WhiteSpace.DisallowTabIndent,
so the fixer emitted indentation its own ruleset then flags, and it used a
column offset as a repeat count, so a doc block indented by four spaces got
four tabs rather than one level.

Both now use the getIndentationWhitespace() helper already used elsewhere for
this, which reads the actual leading whitespace of the line.

The fixture added with the smoke tests recorded the tab output; it now records
the file's own indentation.
Copilot AI lite review requested due to automatic review settings August 6, 2026 11:50
@dereuromark
dereuromark merged commit dda4324 into master Aug 6, 2026
6 checks passed
@dereuromark
dereuromark deleted the doccomment-tab-indentation branch August 6, 2026 11:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DocCommentSniff auto-fixes that previously generated incorrect indentation by (a) emitting tab characters and (b) using a column offset as a repeat count. The updated logic reuses the existing getIndentationWhitespace() helper so fixer output matches the file’s actual leading whitespace and stays compatible with Generic.WhiteSpace.DisallowTabIndent.

Changes:

  • Replace tab-based indentation building with getIndentationWhitespace() in two DocCommentSniff fixing paths.
  • Update the DocComment fixer fixture output to reflect space indentation rather than tab indentation.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
PhpCollective/Sniffs/Commenting/DocCommentSniff.php Switch fixer indentation logic to getIndentationWhitespace() to avoid emitting tabs / incorrect indent depth.
tests/_data/DocComment/after.php Refresh expected “after” fixture to match the corrected indentation output.
Suppressed comments (1)

PhpCollective/Sniffs/Commenting/DocCommentSniff.php:83

  • When splitting an inline close tag onto its own line, the fixer leaves behind the single space that previously separated the last word from */, resulting in trailing whitespace on the preceding * ... line (see tests/_data/DocComment/before.php line 10 vs after.php line 10). Since the ruleset enables Squiz.WhiteSpace.SuperfluousWhitespace (PhpCollective/ruleset.xml:169), this can cause phpcbf to introduce a new whitespace violation that then requires another fixer pass to clean up. Consider also removing any T_DOC_COMMENT_WHITESPACE tokens between $prev and $commentEnd on that same line when applying the ContentBeforeClose fix.
                $phpcsFile->fixer->beginChangeset();

                $phpcsFile->fixer->replaceToken($commentEnd, $indentation . ' ' . $tokens[$commentEnd]['content']);
                $phpcsFile->fixer->addNewlineBefore($commentEnd);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants