From 1eb9b6f8b53758fc493799a57fcc5054273f3f94 Mon Sep 17 00:00:00 2001
From: vkryklyvenko <97754008+vkryklyvenko@users.noreply.github.com>
Date: Wed, 1 Jun 2022 17:14:55 +0300
Subject: [PATCH 1/2] Add no-files option
Add option to able to return exit code 1 if no files processed
---
src/Command/LintCommand.php | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php
index 61962252..05345e36 100644
--- a/src/Command/LintCommand.php
+++ b/src/Command/LintCommand.php
@@ -139,6 +139,12 @@ protected function configure()
'q',
InputOption::VALUE_NONE,
'Allow to silenty fail.'
+ )
+ ->addOption(
+ 'no-files',
+ 'nf',
+ InputOption::VALUE_NONE,
+ 'Throw error if no files processed.'
);
}
@@ -204,11 +210,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$fileCount = count($linter->getFiles());
+ $code = 0;
if ($fileCount <= 0) {
$output->writeln('Could not find files to lint');
-
- return 0;
+
+ if (!empty($options['no-files'])) {
+ $code = 1;
+ }
+
+ return $code;
}
$errors = $this->executeLint($linter, $input, $output, $fileCount);
@@ -216,7 +227,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$timeUsage = Helper::formatTime(microtime(true) - $startTime);
$memUsage = Helper::formatMemory(memory_get_usage(true) - $startMemUsage);
- $code = 0;
$errCount = count($errors);
$output->writeln(sprintf(
From 995b29f50015261cae067179d396208604b86c26 Mon Sep 17 00:00:00 2001
From: vkryklyvenko <97754008+vkryklyvenko@users.noreply.github.com>
Date: Wed, 1 Jun 2022 17:21:21 +0300
Subject: [PATCH 2/2] Rename no-files option
Rename no-files option to no-files-exit-code
---
src/Command/LintCommand.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php
index 05345e36..77518240 100644
--- a/src/Command/LintCommand.php
+++ b/src/Command/LintCommand.php
@@ -141,7 +141,7 @@ protected function configure()
'Allow to silenty fail.'
)
->addOption(
- 'no-files',
+ 'no-files-exit-code',
'nf',
InputOption::VALUE_NONE,
'Throw error if no files processed.'
@@ -215,7 +215,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($fileCount <= 0) {
$output->writeln('Could not find files to lint');
- if (!empty($options['no-files'])) {
+ if (!empty($options['no-files-exit-code'])) {
$code = 1;
}