From a63b8f25367c3321b018a4bb256f5c8a65ccdd1b Mon Sep 17 00:00:00 2001 From: vkryklyvenko <97754008+vkryklyvenko@users.noreply.github.com> Date: Wed, 8 Jun 2022 14:06:56 +0300 Subject: [PATCH] Add no-files-exit-code option Add no-files-exit-code option --- src/Command/LintCommand.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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(