Skip to content

Commit

Permalink
Merge pull request #15 from netgen/NGSTACK-957-git-hooks-node-version…
Browse files Browse the repository at this point in the history
…-error

NGSTACK-957 read and output stderr from eslint and prettier
  • Loading branch information
emodric authored Dec 19, 2024
2 parents 1c1f32c + d883e34 commit 7aa2ebb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Action/JSLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function count;
use function escapeshellarg;
use function preg_match;
use function sprintf;

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

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

$io->write($result['output']);

if ($result['success'] !== true) {
if ($result['success'] === true) {
$io->write($result['output']);
} else {
$io->writeError(sprintf('<error>%s</error>', $result['error']));
$this->throwError($action, $io);
}
}
Expand Down Expand Up @@ -85,6 +87,7 @@ protected function lintFile(string $file, string $linterCommand, string $linterO
return [
'success' => $result->isSuccessful(),
'output' => $result->getStdOut(),
'error' => $result->getStdErr(),
];
}
}
9 changes: 6 additions & 3 deletions src/Action/JSPrettier.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function count;
use function escapeshellarg;
use function preg_match;
use function sprintf;

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

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

$io->write($result['output']);

if ($result['success'] !== true) {
if ($result['success'] === true) {
$io->write($result['output']);
} else {
$io->writeError(sprintf('<error>%s</error>', $result['error']));
$this->throwError($action, $io);
}
}
Expand Down Expand Up @@ -85,6 +87,7 @@ protected function lintFile(string $file, string $prettierCommand, string $prett
return [
'success' => $result->isSuccessful(),
'output' => $result->getStdOut(),
'error' => $result->getStdErr(),
];
}
}

0 comments on commit 7aa2ebb

Please sign in to comment.