From 75ab7e1ba2f58db970543c0da37424b3f98b1656 Mon Sep 17 00:00:00 2001 From: Amalija Ramljak Date: Wed, 26 Jul 2023 14:21:40 +0200 Subject: [PATCH 1/3] NGSTACK-789 add extensions array option --- src/Action/JSLinter.php | 12 +++++++++--- src/Action/JSPrettier.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Action/JSLinter.php b/src/Action/JSLinter.php index 7522bd8..2825780 100644 --- a/src/Action/JSLinter.php +++ b/src/Action/JSLinter.php @@ -19,8 +19,14 @@ final class JSLinter extends Action protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void { - $changedJsFiles = $repository->getIndexOperator()->getStagedFilesOfType('js'); - if (count($changedJsFiles) === 0) { + $extensions = $action->getOptions()->get('extensions', ['js']); + + $changedFiles = []; + foreach ($extensions as $extension) { + $changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension)); + } + + if (count($changedFiles) === 0) { return; } @@ -30,7 +36,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con $linterOptions = $action->getOptions()->get('linter_options', '--fix-dry-run'); $io->write('Running linter on files:', true, IO::VERBOSE); - foreach ($changedJsFiles as $file) { + foreach ($changedFiles as $file) { if ($this->shouldSkipFileCheck($file, $excludedFiles)) { continue; } diff --git a/src/Action/JSPrettier.php b/src/Action/JSPrettier.php index 663eb29..a8d4534 100644 --- a/src/Action/JSPrettier.php +++ b/src/Action/JSPrettier.php @@ -19,8 +19,14 @@ final class JSPrettier extends Action protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void { - $changedJsFiles = $repository->getIndexOperator()->getStagedFilesOfType('js'); - if (count($changedJsFiles) === 0) { + $extensions = $action->getOptions()->get('extensions', ['js']); + + $changedFiles = []; + foreach ($extensions as $extension) { + $changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension)); + } + + if (count($changedFiles) === 0) { return; } @@ -30,7 +36,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con $prettierOptions = $action->getOptions()->get('prettier_options', '--check'); $io->write('Running prettier on files:', true, IO::VERBOSE); - foreach ($changedJsFiles as $file) { + foreach ($changedFiles as $file) { if ($this->shouldSkipFileCheck($file, $excludedFiles)) { continue; } From ff9c98102ff3b68f6269bbe06cce567e023a6037 Mon Sep 17 00:00:00 2001 From: Amalija Ramljak Date: Wed, 20 Mar 2024 11:57:03 +0100 Subject: [PATCH 2/3] NGSTACK-789 run cs fixer --- src/Action/JSLinter.php | 3 ++- src/Action/JSPrettier.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Action/JSLinter.php b/src/Action/JSLinter.php index 2825780..5ee4ac4 100644 --- a/src/Action/JSLinter.php +++ b/src/Action/JSLinter.php @@ -9,6 +9,7 @@ use SebastianFeldmann\Cli\Processor\ProcOpen as Processor; use SebastianFeldmann\Git\Repository; +use function array_merge; use function count; use function escapeshellarg; use function preg_match; @@ -20,7 +21,7 @@ final class JSLinter extends Action protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void { $extensions = $action->getOptions()->get('extensions', ['js']); - + $changedFiles = []; foreach ($extensions as $extension) { $changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension)); diff --git a/src/Action/JSPrettier.php b/src/Action/JSPrettier.php index a8d4534..9174b41 100644 --- a/src/Action/JSPrettier.php +++ b/src/Action/JSPrettier.php @@ -9,6 +9,7 @@ use SebastianFeldmann\Cli\Processor\ProcOpen as Processor; use SebastianFeldmann\Git\Repository; +use function array_merge; use function count; use function escapeshellarg; use function preg_match; @@ -20,7 +21,7 @@ final class JSPrettier extends Action protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void { $extensions = $action->getOptions()->get('extensions', ['js']); - + $changedFiles = []; foreach ($extensions as $extension) { $changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension)); From 44bfeedb92146e4cb6095b9409d920e9c4c0f2e0 Mon Sep 17 00:00:00 2001 From: Amalija Ramljak Date: Wed, 20 Mar 2024 14:37:58 +0100 Subject: [PATCH 3/3] NGSTACK-789 change typehint --- src/Action/Action.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Action/Action.php b/src/Action/Action.php index e4c1b26..07c9eb7 100644 --- a/src/Action/Action.php +++ b/src/Action/Action.php @@ -18,7 +18,7 @@ abstract class Action implements ActionInterface { protected const ERROR_MESSAGE = "I'm sorry, Dave. I'm afraid I can't do that. Please check your commit for errors"; - public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void + public function execute(Config $config, IO $io, Repository $repository, ActionConfig $action): void { if (!$this->isEnabled($action)) { return; @@ -27,7 +27,7 @@ public function execute(Config $config, IO $io, Repository $repository, Config\A $this->doExecute($config, $io, $repository, $action); } - abstract protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void; + abstract protected function doExecute(Config $config, IO $io, Repository $repository, ActionConfig $action): void; protected function throwError(ActionConfig $config, IO $io): void {