From 90d72ca68655e09c0a56d2867736a08c692affb9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 1 Jun 2021 14:03:19 +0200 Subject: [PATCH] Tweak validate command output to be slightly more readable, less colorful --- src/Composer/Command/ValidateCommand.php | 54 ++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 6a37785cd..fdb424423 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -168,36 +168,62 @@ EOT if ($errors) { $io->writeError('' . $name . ' is invalid, the following errors/warnings were found:'); } elseif ($publishErrors) { - $io->writeError('' . $name . ' is valid for simple usage with composer but has'); - $io->writeError('strict errors that make it unable to be published as a package:'); + $io->writeError('' . $name . ' is valid for simple usage with Composer but has'); + $io->writeError('strict errors that make it unable to be published as a package'); $doPrintSchemaUrl = $printSchemaUrl; } elseif ($warnings) { $io->writeError('' . $name . ' is valid, but with a few warnings'); $doPrintSchemaUrl = $printSchemaUrl; + } elseif ($lockErrors) { + $io->write('' . $name . ' is valid but your composer.lock has some '.($checkLock ? 'errors' : 'warnings').''); } else { $io->write('' . $name . ' is valid'); - // if ($lockErrors) then they will be displayed below } if ($doPrintSchemaUrl) { $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); } + if ($errors) { + $errors = array_map(function ($err) { + return '- ' . $err; + }, $errors); + array_unshift($errors, '# General errors'); + } + if ($warnings) { + $warnings = array_map(function ($err) { + return '- ' . $err; + }, $warnings); + array_unshift($warnings, '# General warnings'); + } + // Avoid setting the exit code to 1 in case --strict and --no-check-publish/--no-check-lock are combined $extraWarnings = array(); // If checking publish errors, display them as errors, otherwise just show them as warnings - if ($checkPublish) { - $errors = array_merge($errors, $publishErrors); - } else { - $extraWarnings = array_merge($extraWarnings, $publishErrors); + if ($publishErrors) { + $publishErrors = array_map(function ($err) { + return '- ' . $err; + }, $publishErrors); + + if ($checkPublish) { + array_unshift($publishErrors, '# Publish errors'); + $errors = array_merge($errors, $publishErrors); + } else { + array_unshift($publishErrors, '# Publish warnings'); + $extraWarnings = array_merge($extraWarnings, $publishErrors); + } } // If checking lock errors, display them as errors, otherwise just show them as warnings - if ($checkLock) { - $errors = array_merge($errors, $lockErrors); - } else { - $extraWarnings = array_merge($extraWarnings, $lockErrors); + if ($lockErrors) { + if ($checkLock) { + array_unshift($lockErrors, '# Lock file errors'); + $errors = array_merge($errors, $lockErrors); + } else { + array_unshift($lockErrors, '# Lock file warnings'); + $extraWarnings = array_merge($extraWarnings, $lockErrors); + } } $messages = array( @@ -207,7 +233,11 @@ EOT foreach ($messages as $style => $msgs) { foreach ($msgs as $msg) { - $io->writeError('<' . $style . '>' . $msg . ''); + if (strpos($msg, '#') === 0) { + $io->writeError('<' . $style . '>' . $msg . ''); + } else { + $io->writeError($msg); + } } } }