From 4ec73874cbae382807f3db70121643f1e8befbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Fri, 17 Apr 2020 22:38:14 +0200 Subject: [PATCH 1/3] Add "no-check-version" option to ValidateCommand --- src/Composer/Command/ValidateCommand.php | 6 ++++-- src/Composer/Util/ConfigValidator.php | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 6ab95ed1c..cb178d263 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -42,6 +42,7 @@ class ValidateCommand extends BaseCommand new InputOption('no-check-all', null, InputOption::VALUE_NONE, 'Do not validate requires for overly strict/loose constraints'), new InputOption('no-check-lock', null, InputOption::VALUE_NONE, 'Do not check if lock file is up to date'), new InputOption('no-check-publish', null, InputOption::VALUE_NONE, 'Do not check for publish errors'), + new InputOption('no-check-version', null, InputOption::VALUE_NONE, 'Do not check if version field is present'), new InputOption('with-dependencies', 'A', InputOption::VALUE_NONE, 'Also validate the composer.json of all installed dependencies'), new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code for warnings as well as errors'), new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file'), @@ -86,8 +87,9 @@ EOT $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL; $checkPublish = !$input->getOption('no-check-publish'); $checkLock = !$input->getOption('no-check-lock'); + $checkVersion = !$input->getOption('no-check-version'); $isStrict = $input->getOption('strict'); - list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); + list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion); $lockErrors = array(); $composer = Factory::create($io, $file, $input->hasParameterOption('--no-plugins')); @@ -107,7 +109,7 @@ EOT $path = $composer->getInstallationManager()->getInstallPath($package); $file = $path . '/composer.json'; if (is_dir($path) && file_exists($file)) { - list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); + list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion); $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors); diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index 98a6016f2..4d6998dec 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -40,10 +40,11 @@ class ConfigValidator * * @param string $file The path to the file * @param int $arrayLoaderValidationFlags Flags for ArrayLoader validation + * @param bool $checkVersion Whether or not check if version field is present * * @return array a triple containing the errors, publishable errors, and warnings */ - public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL) + public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL, $checkVersion = true) { $errors = array(); $publishErrors = array(); @@ -109,7 +110,7 @@ class ConfigValidator } } - if (isset($manifest['version'])) { + if ($checkVersion && isset($manifest['version'])) { $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.'; } From a54bf0e2d4003c9a442a96f3501a90667048e965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 18 Apr 2020 09:24:54 +0200 Subject: [PATCH 2/3] Use flags instead of boolean in ConfigValidator for checking version field --- src/Composer/Command/ValidateCommand.php | 2 +- src/Composer/Util/ConfigValidator.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index cb178d263..8da0854a3 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -87,7 +87,7 @@ EOT $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL; $checkPublish = !$input->getOption('no-check-publish'); $checkLock = !$input->getOption('no-check-lock'); - $checkVersion = !$input->getOption('no-check-version'); + $checkVersion = $input->getOption('no-check-version') ? 0 : ConfigValidator::CHECK_VERSION; $isStrict = $input->getOption('strict'); list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion); diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index 4d6998dec..aae5879b3 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -28,6 +28,8 @@ use Composer\Spdx\SpdxLicenses; */ class ConfigValidator { + const CHECK_VERSION = 1; + private $io; public function __construct(IOInterface $io) @@ -40,11 +42,11 @@ class ConfigValidator * * @param string $file The path to the file * @param int $arrayLoaderValidationFlags Flags for ArrayLoader validation - * @param bool $checkVersion Whether or not check if version field is present + * @param int $flags Flags for validation * * @return array a triple containing the errors, publishable errors, and warnings */ - public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL, $checkVersion = true) + public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL, $flags = self::CHECK_VERSION) { $errors = array(); $publishErrors = array(); @@ -110,7 +112,7 @@ class ConfigValidator } } - if ($checkVersion && isset($manifest['version'])) { + if (($flags & self::CHECK_VERSION) && isset($manifest['version'])) { $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.'; } From c12a1a6d64dc87fb7e5d63f4ab6c9e701adc9f3a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 18 Apr 2020 14:41:04 +0200 Subject: [PATCH 3/3] Update flag description --- src/Composer/Command/ValidateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 8da0854a3..1c76d678d 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -42,7 +42,7 @@ class ValidateCommand extends BaseCommand new InputOption('no-check-all', null, InputOption::VALUE_NONE, 'Do not validate requires for overly strict/loose constraints'), new InputOption('no-check-lock', null, InputOption::VALUE_NONE, 'Do not check if lock file is up to date'), new InputOption('no-check-publish', null, InputOption::VALUE_NONE, 'Do not check for publish errors'), - new InputOption('no-check-version', null, InputOption::VALUE_NONE, 'Do not check if version field is present'), + new InputOption('no-check-version', null, InputOption::VALUE_NONE, 'Do not report a warning if the version field is present'), new InputOption('with-dependencies', 'A', InputOption::VALUE_NONE, 'Also validate the composer.json of all installed dependencies'), new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code for warnings as well as errors'), new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file'),