Skip to content

Commit

Permalink
DX: Validate paths in RectorConfig->paths() (#5065)
Browse files Browse the repository at this point in the history
* Validate paths in RectorConfig->paths()

* added e2e test

* Update e2e.yaml

* Update expected-output.diff

* Update expected-output.diff

* Update expected-output.diff
  • Loading branch information
staabm committed Sep 24, 2023
1 parent 061eea0 commit 0d9b38d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- 'e2e/applied-rule-removed-node'
- 'e2e/parallel with space'
- 'e2e/different-path-over-skip-config'
- 'e2e/invalid-paths'

name: End to end test - ${{ matrix.directory }}

Expand Down
1 change: 1 addition & 0 deletions e2e/invalid-paths/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
5 changes: 5 additions & 0 deletions e2e/invalid-paths/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
3 changes: 3 additions & 0 deletions e2e/invalid-paths/expected-output.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ERROR] The file
"./invalid-paths/does-not-exi
st/" does not exist.
15 changes: 15 additions & 0 deletions e2e/invalid-paths/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->disableParallel();

$rectorConfig->paths([
__DIR__ . '/src/', // correct path
__DIR__ . '/does-not-exist/'
]);
};
10 changes: 10 additions & 0 deletions e2e/invalid-paths/src/NamespacedSomeClassFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace E2e\Parallel\Reflection\Resolver;

final class NamespacedSomeClassFound
{
private $foo;
}
9 changes: 9 additions & 0 deletions packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ final class RectorConfig extends Container
public function paths(array $paths): void
{
Assert::allString($paths);

foreach($paths as $path) {
if (str_contains($path, '*')) {
continue;
}

Assert::fileExists($path);
}

SimpleParameterProvider::setParameter(Option::PATHS, $paths);
}

Expand Down

0 comments on commit 0d9b38d

Please sign in to comment.