Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public function run(Configuration $configuration, InputInterface $input): Proces

$processResult->addSystemErrors($this->systemErrors);

// path-only skips are matched in the main process while finding files; in parallel runs the
// result comes from workers only, so merge those marks back in to avoid false "unused skip"
$processResult->addUsedSkips($this->usedSkipCollector->provide());

$this->restoreErrorHandler();

return $processResult;
Expand Down
6 changes: 4 additions & 2 deletions src/Reporting/UnusedSkipResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\FileSystem\FilePathHelper;
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver;
use Rector\ValueObject\ProcessResult;
Expand All @@ -18,6 +19,7 @@
public function __construct(
private SkippedClassResolver $skippedClassResolver,
private SkippedPathsResolver $skippedPathsResolver,
private FilePathHelper $filePathHelper,
) {
}

Expand Down Expand Up @@ -47,7 +49,7 @@ public function resolve(ProcessResult $processResult): array

// rule-scoped paths are intentional, so they are reported even as mask paths
foreach ($paths as $path) {
$skipDisplaysByPath[$path] = $rectorClass . ' => ' . $path;
$skipDisplaysByPath[$path] = $rectorClass . ' => ' . $this->filePathHelper->relativePath($path);
}
}

Expand All @@ -57,7 +59,7 @@ public function resolve(ProcessResult $processResult): array
continue;
}

$skipDisplaysByPath[$globalPath] = $globalPath;
$skipDisplaysByPath[$globalPath] = $this->filePathHelper->relativePath($globalPath);
}

$usedSkips = $processResult->getUsedSkips();
Expand Down
16 changes: 15 additions & 1 deletion src/ValueObject/ProcessResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
private array $systemErrors,
private readonly array $fileDiffs,
private readonly int $totalChanged,
private readonly array $usedSkips = []
private array $usedSkips = []
) {
Assert::allIsInstanceOf($systemErrors, SystemError::class);
Assert::allIsInstanceOf($fileDiffs, FileDiff::class);
Expand Down Expand Up @@ -57,6 +57,20 @@ public function addSystemErrors(array $systemErrors): void
$this->systemErrors = [...$this->systemErrors, ...$systemErrors];
}

/**
* Path-only skips are matched while finding files in the main process, but parallel runs build
* their result from worker processes only. Merge those main-process marks back in, or they would
* be wrongly reported as unused.
*
* @param string[] $usedSkips
*/
public function addUsedSkips(array $usedSkips): void
{
Assert::allString($usedSkips);

$this->usedSkips = array_values(array_unique([...$this->usedSkips, ...$usedSkips]));
}

public function getTotalChanged(): int
{
return $this->totalChanged;
Expand Down
15 changes: 15 additions & 0 deletions tests/Reporting/UnusedSkipResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public function testResolvesUnusedSkipsAsRuleAndPath(): void
$this->assertNotContains(ThreeMan::class, $unusedSkips);
}

public function testReportsUnusedSkipAsRelativePath(): void
{
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, true);

$absolutePath = getcwd() . '/src/Reporting/UnusedSkipResolver.php';
SimpleParameterProvider::setParameter(Option::SKIP, [
FifthElement::class => [$absolutePath],
]);

$unusedSkips = $this->unusedSkipResolver->resolve(new ProcessResult([], [], 0, []));

// the absolute path is shortened to a relative one, matching the "->withSkip()" syntax
$this->assertContains(FifthElement::class . ' => src/Reporting/UnusedSkipResolver.php', $unusedSkips);
}

public function testResolvesNothingWhenDisabled(): void
{
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, false);
Expand Down
Loading