Skip to content

Commit

Permalink
Fail TLint fix on linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
driftingly committed Apr 26, 2024
1 parent b12d519 commit 1ea0bbd
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions app/Support/TLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Tighten\TLint\Commands\BaseCommand;
use Tighten\TLint\Commands\FormatCommand;
use Tighten\TLint\Commands\LintCommand;

Expand All @@ -28,20 +29,46 @@ public function fix(): int
private function process(string $command): int
{
$tlintCommand = $command === 'lint' ? new LintCommand : new FormatCommand;
$tlintCommand->config->excluded = [...$tlintCommand->config->excluded ?? [], ...$this->dusterConfig->get('exclude', [])];
$success = $this->executeCommand($tlintCommand);

if ($success && $tlintCommand instanceof FormatCommand) {
$this->success('Checking for any remaining issues after fixing...');
if (! $this->executeCommand(new LintCommand)) {
$this->failure('Some issues could not be fixed automatically.');

return Command::FAILURE;
}
}

return $success ? Command::SUCCESS : Command::FAILURE;
}

private function executeCommand(BaseCommand $tlintCommand): bool
{
$tlintCommand->config->excluded = [
...$tlintCommand->config->excluded ?? [],
...$this->dusterConfig->get('exclude', []),
];

$application = new Application;
$application->add($tlintCommand);
$application->setAutoExit(false);

$success = collect($this->dusterConfig->get('paths'))->map(function ($path) use ($application, $command) {
$path = '"' . str_replace('\\', '\\\\', $path) . '"';

return $application->run(new StringInput("{$command} {$path}"), app()->get(OutputInterface::class));
})
return collect($this->dusterConfig->get('paths'))
->map(fn ($path) => $this->executeCommandOnPath($path, $application))
->filter()
->isEmpty();
}

return $success ? Command::SUCCESS : Command::FAILURE;
private function executeCommandOnPath(string $path, Application $application): int
{
$path = '"' . str_replace('\\', '\\\\', $path) . '"';

$command = $application->has('lint') ? 'lint' : 'format';

return $application->run(
new StringInput("{$command} {$path}"),
app()->get(OutputInterface::class)
);
}
}

0 comments on commit 1ea0bbd

Please sign in to comment.