Skip to content

Commit

Permalink
Add skipped Rectors to list-rules (#3162)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 6, 2022
1 parent d3abaa1 commit 44c95d4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Console/Command/ListRulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -23,6 +24,7 @@ final class ListRulesCommand extends Command
*/
public function __construct(
private readonly RectorOutputStyle $rectorOutputStyle,
private readonly SkippedClassResolver $skippedClassResolver,
private readonly array $rectors
) {
parent::__construct();
Expand All @@ -46,10 +48,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$rectorClasses = $this->resolveRectorClasses();

$skippedClasses = $this->getSkippedCheckers();

$outputFormat = $input->getOption(Option::OUTPUT_FORMAT);
if ($outputFormat === 'json') {
$data = [
'rectors' => $rectorClasses,
'skipped-rectors' => $skippedClasses,
];

echo Json::encode($data, Json::PRETTY) . PHP_EOL;
Expand All @@ -59,6 +64,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->rectorOutputStyle->title('Loaded Rector rules');
$this->rectorOutputStyle->listing($rectorClasses);

if ($skippedClasses !== []) {
$this->rectorOutputStyle->title('Skipped Rector rules');
$this->rectorOutputStyle->listing($skippedClasses);
}

return Command::SUCCESS;
}

Expand All @@ -83,4 +93,22 @@ static function (RectorInterface $rector): bool {

return $rectorClasses;
}

/**
* @return string[]
*/
private function getSkippedCheckers(): array
{
$skippedCheckers = [];
foreach ($this->skippedClassResolver->resolve() as $checkerClass => $fileList) {
// ignore specific skips
if ($fileList !== null) {
continue;
}

$skippedCheckers[] = $checkerClass;
}

return $skippedCheckers;
}
}

0 comments on commit 44c95d4

Please sign in to comment.