Skip to content

Commit 4a46c83

Browse files
committed
Report Full: fix max report width not being respected when showing sources
1 parent ad82ca1 commit 4a46c83

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Reports/Full.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,31 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
114114

115115
// The maximum amount of space an error message can use.
116116
$maxErrorSpace = ($width - $paddingLength - 1);
117-
if ($showSources === true) {
118-
// Account for the chars used to print colors.
119-
$maxErrorSpace += 8;
120-
}
121117

122118
foreach ($report['messages'] as $line => $lineErrors) {
123119
foreach ($lineErrors as $column => $colErrors) {
124120
foreach ($colErrors as $error) {
125-
$message = $error['message'];
126-
if ($showSources === true) {
127-
$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
128-
}
129-
121+
$message = $error['message'];
130122
$msgLines = [$message];
131123
if (strpos($message, "\n") !== false) {
132124
$msgLines = explode("\n", $message);
133125
}
134126

135127
$errorMsg = '';
128+
$lastLine = (count($msgLines) - 1);
136129
foreach ($msgLines as $k => $msgLine) {
137-
if ($k !== 0) {
130+
if ($k === 0) {
131+
if ($showSources === true) {
132+
$errorMsg .= "\033[1m";
133+
}
134+
} else {
138135
$errorMsg .= PHP_EOL.$paddingLine2;
139136
}
140137

138+
if ($k === $lastLine && $showSources === true) {
139+
$msgLine .= "\033[0m".' ('.$error['source'].')';
140+
}
141+
141142
$errorMsg .= wordwrap(
142143
$msgLine,
143144
$maxErrorSpace,

0 commit comments

Comments
 (0)