phprector

PHP Rector combine path and skip


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.


Solution

  • 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/**/*',
        ]);