Skip to content

Commit

Permalink
Report Full: iterate on line wrapping bug fix [3]
Browse files Browse the repository at this point in the history
Don't hard code the color code length to prevent this breaking on potential future changes.

Co-authored-by: Brad Jorsch <[email protected]>
  • Loading branch information
jrfnl and anomiex committed Dec 11, 2023
1 parent b9dd7db commit 0ba5736
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Reports/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
$afterMsg = "\033[0m";
}

$beforeAfterLength = strlen($beforeMsg.$afterMsg);

foreach ($report['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
Expand Down Expand Up @@ -150,7 +152,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
// Add space + source suffix length.
$lastMsgPlusSourceLength += (1 + strlen($sourceSuffix));
// Correct for the color codes.
$lastMsgPlusSourceLength -= 8;
$lastMsgPlusSourceLength -= $beforeAfterLength;

if ($lastMsgPlusSourceLength > $maxErrorSpace) {
$errorMsg .= PHP_EOL.$paddingLine2.$sourceSuffix;
Expand Down

0 comments on commit 0ba5736

Please sign in to comment.