Add "no-check-version" option to ValidateCommand

main
Kuba Werłos 4 years ago
parent 12be472c6b
commit 4ec73874cb

@ -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-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-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-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('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 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'), 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; $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
$checkPublish = !$input->getOption('no-check-publish'); $checkPublish = !$input->getOption('no-check-publish');
$checkLock = !$input->getOption('no-check-lock'); $checkLock = !$input->getOption('no-check-lock');
$checkVersion = !$input->getOption('no-check-version');
$isStrict = $input->getOption('strict'); $isStrict = $input->getOption('strict');
list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion);
$lockErrors = array(); $lockErrors = array();
$composer = Factory::create($io, $file, $input->hasParameterOption('--no-plugins')); $composer = Factory::create($io, $file, $input->hasParameterOption('--no-plugins'));
@ -107,7 +109,7 @@ EOT
$path = $composer->getInstallationManager()->getInstallPath($package); $path = $composer->getInstallationManager()->getInstallPath($package);
$file = $path . '/composer.json'; $file = $path . '/composer.json';
if (is_dir($path) && file_exists($file)) { 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); $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors);

@ -40,10 +40,11 @@ class ConfigValidator
* *
* @param string $file The path to the file * @param string $file The path to the file
* @param int $arrayLoaderValidationFlags Flags for ArrayLoader validation * @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 * @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(); $errors = array();
$publishErrors = 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.'; $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.';
} }

Loading…
Cancel
Save