PHP Rector combine path and skip

3k Views Asked by At

I have a PHP Symfony project with much vendor and other sub dir files which should not bee touched by rector. So I setup the path variable to only check files within a specific folder tree. That works fine.

    return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/plugins/*',
    ]);

But since this folder contains plugins which may have their own vendor & test directories, I want to skip these. Regarding the docs https://github.com/rectorphp/rector/blob/main/docs/how_to_ignore_rule_or_paths.md skip with wildcards is possible, but these skip rules will be ignored totally.

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/plugins/*',
    ]);

    $rectorConfig->skip([
        __DIR__ . '/plugins/*/tests',
        __DIR__ . '/plugins/*/vendor',
    ]);

What could be wrong with my config? Or does rector not allow to combine these options? The documentation doesn't provide such a case.

2

There are 2 best solutions below

1
On BEST ANSWER

After a while I found out that skip doesn't work with directories but with files. So the following configuration works.

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/plugins/*',
    ]);

    $rectorConfig->skip([
        __DIR__ . '/plugins/*/tests/**/*',
        __DIR__ . '/plugins/*/vendor/**/*',
    ]);
0
On

Skip works with directories and files:

return static function (RectorConfig $rectorConfig): void 
{
    $rectorConfig->skip([
        __DIR__ . '/src/SingleFile.php',
        __DIR__ . '/src/Single_Directory_Skip',
        // or use fnmatch
        __DIR__ . '/src/*/Tests/*',
    ]);
    
    $rectorConfig->paths([
        __DIR__ . '/single_file_check.php',
        __DIR__ . '/some_directoryCheck',
    ]);

Yours Fixed:

    $rectorConfig->paths([
        __DIR__ . '/plugins',
    ]);