Skip to content

Commit ad82ca1

Browse files
committed
Report Full: fix word wrapping when message contains new lines
The word wrapping was causing unexpected and unintended message formatting if the message contained new lines.
1 parent 239b570 commit ad82ca1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/Reports/Full.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,30 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
123123
foreach ($lineErrors as $column => $colErrors) {
124124
foreach ($colErrors as $error) {
125125
$message = $error['message'];
126-
$message = str_replace("\n", "\n".$paddingLine2, $message);
127126
if ($showSources === true) {
128127
$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
129128
}
130129

130+
$msgLines = [$message];
131+
if (strpos($message, "\n") !== false) {
132+
$msgLines = explode("\n", $message);
133+
}
134+
135+
$errorMsg = '';
136+
foreach ($msgLines as $k => $msgLine) {
137+
if ($k !== 0) {
138+
$errorMsg .= PHP_EOL.$paddingLine2;
139+
}
140+
141+
$errorMsg .= wordwrap(
142+
$msgLine,
143+
$maxErrorSpace,
144+
PHP_EOL.$paddingLine2
145+
);
146+
}
147+
131148
// The padding that goes on the front of the line.
132-
$padding = ($maxLineNumLength - strlen($line));
133-
$errorMsg = wordwrap(
134-
$message,
135-
$maxErrorSpace,
136-
PHP_EOL.$paddingLine2
137-
);
149+
$padding = ($maxLineNumLength - strlen($line));
138150

139151
echo ' '.str_repeat(' ', $padding).$line.' | ';
140152
if ($error['type'] === 'ERROR') {

0 commit comments

Comments
 (0)