Skip to content

Commit 75ab7e1

Browse files
NGSTACK-789 add extensions array option
1 parent 23f6f25 commit 75ab7e1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/Action/JSLinter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ final class JSLinter extends Action
1919

2020
protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void
2121
{
22-
$changedJsFiles = $repository->getIndexOperator()->getStagedFilesOfType('js');
23-
if (count($changedJsFiles) === 0) {
22+
$extensions = $action->getOptions()->get('extensions', ['js']);
23+
24+
$changedFiles = [];
25+
foreach ($extensions as $extension) {
26+
$changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension));
27+
}
28+
29+
if (count($changedFiles) === 0) {
2430
return;
2531
}
2632

@@ -30,7 +36,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
3036
$linterOptions = $action->getOptions()->get('linter_options', '--fix-dry-run');
3137

3238
$io->write('Running linter on files:', true, IO::VERBOSE);
33-
foreach ($changedJsFiles as $file) {
39+
foreach ($changedFiles as $file) {
3440
if ($this->shouldSkipFileCheck($file, $excludedFiles)) {
3541
continue;
3642
}

src/Action/JSPrettier.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ final class JSPrettier extends Action
1919

2020
protected function doExecute(Config $config, IO $io, Repository $repository, Config\Action $action): void
2121
{
22-
$changedJsFiles = $repository->getIndexOperator()->getStagedFilesOfType('js');
23-
if (count($changedJsFiles) === 0) {
22+
$extensions = $action->getOptions()->get('extensions', ['js']);
23+
24+
$changedFiles = [];
25+
foreach ($extensions as $extension) {
26+
$changedFiles = array_merge($changedFiles, $repository->getIndexOperator()->getStagedFilesOfType($extension));
27+
}
28+
29+
if (count($changedFiles) === 0) {
2430
return;
2531
}
2632

@@ -30,7 +36,7 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
3036
$prettierOptions = $action->getOptions()->get('prettier_options', '--check');
3137

3238
$io->write('Running prettier on files:', true, IO::VERBOSE);
33-
foreach ($changedJsFiles as $file) {
39+
foreach ($changedFiles as $file) {
3440
if ($this->shouldSkipFileCheck($file, $excludedFiles)) {
3541
continue;
3642
}

0 commit comments

Comments
 (0)