diff --git a/app/Support/TLint.php b/app/Support/TLint.php index 6fe294d..2fda156 100644 --- a/app/Support/TLint.php +++ b/app/Support/TLint.php @@ -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; @@ -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) + ); } }