rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.61k stars 680 forks source link

Remove "/vendor" from Rector paths and run again. #8494

Closed parth391 closed 7 months ago

parth391 commented 7 months ago

Question

Getting bellow warning on, vendor/bin/rector process

[WARNING] Rector is running on your "/vendor" directory. This is not
          necessary, as Rector access /vendor by composer autoload. It will
          cause Rector tu run much slower and possibly with errors.
          Remove "/vendor" from Rector paths and run again.`
samsonasik commented 7 months ago

That means you need to exclude __DIR__ . '/vendor from the paths when possible in the rector config, eg, only src paths:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src',
    ])
    ->withRules([
        TypedPropertyFromAssignsRector::class
    ]);

If you have vendor/ but not in the root directory, like what laravel vendor in templates part, you can try latest rector/rector:dev-main that already cover it at PR:

with

composer config minimum-stability dev
composer config prefer-stable true
composer require --dev rector/rector:dev-main

If you have vendor/ that needs code upgrade, I suggest to upgrade the version of dependency instead.

samsonasik commented 7 months ago

Could you create a reproducible repo?

parth391 commented 7 months ago

@samsonasik, one of my sub-folder had a vendor folder in it. By adding bellow code fix the issue.

$rectorConfig->skip([
    __DIR__.'/**/vendor/*',
]);
samsonasik commented 6 months ago

That already handled on latest dev-main 👍

parth391 commented 6 months ago

Yes, i am looking forward for new release.

samsonasik commented 6 months ago

1.0.1 is tagged https://github.com/rectorphp/rector/releases/tag/1.0.1