Skip to content

Commit

Permalink
NGSTACK-938 fix phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JakovKnezovicc committed Dec 13, 2024
1 parent 5a28d30 commit d15c095
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Action/CheckLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Act
}

/**
* @param string[] $directories
*
* @return array<string, mixed>
*/
protected function checkLinter(array $directories, string $linterCommand): array
Expand Down
21 changes: 17 additions & 4 deletions src/Action/CheckPrettier.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,37 @@ final class CheckPrettier extends Action

protected function doExecute(Config $config, IO $io, Repository $repository, ActionConfig $action): void
{
/** @var string|string[] $extensions */
$extensions = $action->getOptions()->get('extensions', ['js', 'jsx', 'ts', 'tsx', 'css', 'scss']);
$excludedFiles = $action->getOptions()->get('excluded_files') ?? [];
$directories = $action->getOptions()->get('directories', ['assets']);
$prettierCommand = $action->getOptions()->get('prettier_command', 'pnpm prettier');
$formatOptions = $action->getOptions()->get('prettier_options', '--check');

$finder = new Finder();
$finder->in($directories)->files()->name(preg_filter('/^/', '*.', $extensions));
preg_filter('/^/', '*.', $extensions);
$finder->in($directories)->files()->name($extensions);

if ($finder->hasResults()) {
$io->write(sprintf('Running %s on files:', $prettierCommand), true, IO::VERBOSE);
$io->write(sprintf('Running %s on files:', $prettierCommand));

foreach ($finder as $file) {
if ($this->shouldSkipFileCheck($file, $excludedFiles)) {
if ($this->shouldSkipFileCheck($file->getPath(), $excludedFiles)) {
continue;
}

$result = $this->checkPrettier($file->getPath(), $prettierCommand, $formatOptions);
$io->write($result['output']);

$io->write(sprintf('<info>%s: </info>', $file->getPath()));

/** @var bool $isResultSuccess */
$isResultSuccess = $result['success'];

if ($isResultSuccess) {
$io->write($result['output']);
} else {
$io->writeError(sprintf('<error>%s</error>', $result['error']));
}

if ($result['success'] !== true) {
$this->throwError($action, $io);
Expand Down Expand Up @@ -82,6 +94,7 @@ protected function checkPrettier(string $file, string $prettierCommand, string $
return [
'success' => $result->isSuccessful(),
'output' => $result->getStdOut(),
'error' => $result->getStdErr(),
];
}
}

0 comments on commit d15c095

Please sign in to comment.