fix: Remove trailing spaces from empty docblock lines (#30)

When DocBlock text contains empty lines, str_replace replaces each newline
with a newline followed by ' * ', producing ' * ' (with trailing space) for
empty lines. This triggers trailing-whitespace linters.

Added a preg_replace after each str_replace call to strip trailing horizontal
whitespace from lines that consist only of ' *' followed by spaces.
This commit is contained in:
isaackaara
2026-03-05 12:30:11 +01:00
committed by GitHub
parent d103774cbe
commit 700b4e071f
@@ -206,6 +206,7 @@ class Serializer
$text = wordwrap($text, $wrapLength);
}
$text = str_replace("\n", "\n{$indent} * ", $text);
$text = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $text);
$comment = !empty($text)? "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n" : "{$firstIndent}/**\n";
@@ -220,6 +221,7 @@ class Serializer
$tagText = wordwrap($tagText, $wrapLength);
}
$tagText = str_replace("\n", "\n{$indent} * ", $tagText);
$tagText = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $tagText);
$comment .= "{$indent} * {$tagText}\n";