diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index c1467ff2..c8314ac2 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -113,6 +113,12 @@ protected function configure(): void 'q', InputOption::VALUE_NONE, 'Allow to silently fail.' + ) + ->addOption( + 'no-files-exit-code', + 'nf', + InputOption::VALUE_NONE, + 'Throw error if no files processed.' ); } @@ -153,11 +159,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $fileCount = count($linter->getFiles()); + $code = 0; if ($fileCount <= 0) { $output->writeln('Could not find files to lint'); - return 0; + if (!empty($options['no-files-exit-code'])) { + $code = 1; + } + + return $code; } $errors = $this->executeLint($linter, $input, $output, $fileCount); @@ -165,7 +176,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $timeUsage = Helper::formatTime(microtime(true) - $startTime); $memUsage = Helper::formatMemory(memory_get_usage(true) - $startMemUsage); - $code = 0; $errCount = count($errors); $output->writeln(sprintf(