From 50c808341456643f2338c1b360fc3f9921cc4ad2 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Thu, 6 Aug 2026 13:50:32 +0200 Subject: [PATCH] Fix DocComment fixer emitting tab indentation 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. --- PhpCollective/Sniffs/Commenting/DocCommentSniff.php | 5 ++--- tests/_data/DocComment/after.php | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/PhpCollective/Sniffs/Commenting/DocCommentSniff.php b/PhpCollective/Sniffs/Commenting/DocCommentSniff.php index 82df3b8..c30432b 100644 --- a/PhpCollective/Sniffs/Commenting/DocCommentSniff.php +++ b/PhpCollective/Sniffs/Commenting/DocCommentSniff.php @@ -75,8 +75,7 @@ public function process(File $phpcsFile, $stackPtr): void $error = 'The close comment tag must be the only content on the line'; $fix = $phpcsFile->addFixableError($error, $commentEnd, 'ContentBeforeClose'); if ($fix === true) { - $indentation = $tokens[$commentStart]['column'] - 1; - $indentation = str_repeat("\t", $indentation); + $indentation = $this->getIndentationWhitespace($phpcsFile, $commentStart); $phpcsFile->fixer->beginChangeset(); @@ -167,7 +166,7 @@ public function process(File $phpcsFile, $stackPtr): void $phpcsFile->fixer->replaceToken($i, ''); } - $indent = str_repeat("\t", $tokens[$stackPtr]['column'] - 1) . ' '; + $indent = $this->getIndentationWhitespace($phpcsFile, $stackPtr) . ' '; $phpcsFile->fixer->addContent($prev, $phpcsFile->eolChar . $indent . '*' . $phpcsFile->eolChar); $phpcsFile->fixer->endChangeset(); } diff --git a/tests/_data/DocComment/after.php b/tests/_data/DocComment/after.php index 4867b1c..c98f2f1 100644 --- a/tests/_data/DocComment/after.php +++ b/tests/_data/DocComment/after.php @@ -8,7 +8,7 @@ class DocCommentExample { /** * Close tag shares a line. - */ + */ public function closeTagSharesLine(): void { } @@ -29,7 +29,7 @@ public function extraBlankLineAtEnd(): void /** * Tags are too close. - * + * * @return void */ public function tagsNeedSpacing(): void