Skip to content

Commit 7aa2ebb

Browse files
authored
Merge pull request #15 from netgen/NGSTACK-957-git-hooks-node-version-error
NGSTACK-957 read and output stderr from eslint and prettier
2 parents 1c1f32c + d883e34 commit 7aa2ebb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Action/JSLinter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function count;
1414
use function escapeshellarg;
1515
use function preg_match;
16+
use function sprintf;
1617

1718
final class JSLinter extends Action
1819
{
@@ -44,9 +45,10 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
4445

4546
$result = $this->lintFile($file, $linterCommand, $linterOptions);
4647

47-
$io->write($result['output']);
48-
49-
if ($result['success'] !== true) {
48+
if ($result['success'] === true) {
49+
$io->write($result['output']);
50+
} else {
51+
$io->writeError(sprintf('<error>%s</error>', $result['error']));
5052
$this->throwError($action, $io);
5153
}
5254
}
@@ -85,6 +87,7 @@ protected function lintFile(string $file, string $linterCommand, string $linterO
8587
return [
8688
'success' => $result->isSuccessful(),
8789
'output' => $result->getStdOut(),
90+
'error' => $result->getStdErr(),
8891
];
8992
}
9093
}

src/Action/JSPrettier.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function count;
1414
use function escapeshellarg;
1515
use function preg_match;
16+
use function sprintf;
1617

1718
final class JSPrettier extends Action
1819
{
@@ -44,9 +45,10 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Con
4445

4546
$result = $this->lintFile($file, $prettierCommand, $prettierOptions);
4647

47-
$io->write($result['output']);
48-
49-
if ($result['success'] !== true) {
48+
if ($result['success'] === true) {
49+
$io->write($result['output']);
50+
} else {
51+
$io->writeError(sprintf('<error>%s</error>', $result['error']));
5052
$this->throwError($action, $io);
5153
}
5254
}
@@ -85,6 +87,7 @@ protected function lintFile(string $file, string $prettierCommand, string $prett
8587
return [
8688
'success' => $result->isSuccessful(),
8789
'output' => $result->getStdOut(),
90+
'error' => $result->getStdErr(),
8891
];
8992
}
9093
}

0 commit comments

Comments
 (0)