Skip to content

Commit

Permalink
Hide publish errors entirely with --no-check-publish instead of downg…
Browse files Browse the repository at this point in the history
…rading to warning, fixes #12196
  • Loading branch information
Seldaek committed Dec 11, 2024
1 parent 99430ca commit 8eedfd0
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/Composer/Command/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$file = $input->getArgument('file') ?: Factory::getComposerFile();
$file = $input->getArgument('file') ?? Factory::getComposerFile();
$io = $this->getIO();

if (!file_exists($file)) {
Expand Down Expand Up @@ -144,16 +144,16 @@ private function outputResult(IOInterface $io, string $name, array &$errors, arr
{
$doPrintSchemaUrl = false;

if ($errors) {
if (\count($errors) > 0) {
$io->writeError('<error>' . $name . ' is invalid, the following errors/warnings were found:</error>');
} elseif ($publishErrors) {
} elseif (\count($publishErrors) > 0) {
$io->writeError('<info>' . $name . ' is valid for simple usage with Composer but has</info>');
$io->writeError('<info>strict errors that make it unable to be published as a package</info>');
$doPrintSchemaUrl = $printSchemaUrl;
} elseif ($warnings) {
} elseif (\count($warnings) > 0) {
$io->writeError('<info>' . $name . ' is valid, but with a few warnings</info>');
$doPrintSchemaUrl = $printSchemaUrl;
} elseif ($lockErrors) {
} elseif (\count($lockErrors) > 0) {
$io->write('<info>' . $name . ' is valid but your composer.lock has some '.($checkLock ? 'errors' : 'warnings').'</info>');
} else {
$io->write('<info>' . $name . ' is valid</info>');
Expand All @@ -163,13 +163,13 @@ private function outputResult(IOInterface $io, string $name, array &$errors, arr
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
}

if ($errors) {
if (\count($errors) > 0) {
$errors = array_map(static function ($err): string {
return '- ' . $err;
}, $errors);
array_unshift($errors, '# General errors');
}
if ($warnings) {
if (\count($warnings) > 0) {
$warnings = array_map(static function ($err): string {
return '- ' . $err;
}, $warnings);
Expand All @@ -180,22 +180,17 @@ private function outputResult(IOInterface $io, string $name, array &$errors, arr
$extraWarnings = [];

// If checking publish errors, display them as errors, otherwise just show them as warnings
if ($publishErrors) {
if (\count($publishErrors) > 0 && $checkPublish) {
$publishErrors = array_map(static function ($err): string {
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);
}
array_unshift($publishErrors, '# Publish errors');
$errors = array_merge($errors, $publishErrors);
}

// If checking lock errors, display them as errors, otherwise just show them as warnings
if ($lockErrors) {
if (\count($lockErrors) > 0) {
if ($checkLock) {
array_unshift($lockErrors, '# Lock file errors');
$errors = array_merge($errors, $lockErrors);
Expand Down

0 comments on commit 8eedfd0

Please sign in to comment.