rector: Unexpected behavior when using `-e` option
Bug Report
Subject | Details |
---|---|
Rector version | 0.7.3 (invoke vendor/bin/rector --version ) |
Installed as | prefixed Rector PHAR |
Minimal PHP Code Causing Issue
I don’t know how to create a small demo from this.
I created 3 very similar tests using Github Actions, that demonstrate the issue:
The demo is using Drupal and a module called metatag
.
When testing a certain path in this module there’s another library missing drupal/console
.
- Running Rector with
drupal/console
library - results in expected behavior - no changes are needed. Test: https://github.com/rectorphp/rector/runs/484080076?check_suite_focus=true#step:4:237
[OK] Rector is done!
- Running Rector without
drupal/console
library - results in expected behavior - error that autoload files are missing. Test: https://github.com/rectorphp/rector/runs/484080045?check_suite_focus=true#step:4:206
[ERROR] Could not process
"/home/runner/work/rector/rector/test-paths/drupal-rector073/web/module
s/contrib/metatag/src/Generator/MetatagGroupGenerator.php" file, due
to:
"Analyze error: "Class Drupal\Console\Core\Generator\Generator not
found and could not be autoloaded.". Include your files in "parameters
> autoload_paths".
See https://github.com/rectorphp/rector#extra-autoloading".
[ERROR] Could not process
"/home/runner/work/rector/rector/test-paths/drupal-rector073/web/module
s/contrib/metatag/src/Generator/MetatagTagGenerator.php" file, due to:
"Analyze error: "Class Drupal\Console\Core\Generator\Generator not
found and could not be autoloaded.". Include your files in "parameters
> autoload_paths".
See https://github.com/rectorphp/rector#extra-autoloading".
- But running Rector without
drupal/console
library and with the option-e
- results in unexpected behavior - it seems like Rector runs code linting rule or something, which was not in the config file. Test: https://github.com/rectorphp/rector/runs/484079970?check_suite_focus=true#step:4:206
use Drupal\Console\Core\Generator\Generator;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\TwigRenderer;
-
/**
* Drupal Console plugin for generating a group.
*/
-class MetatagGroupGenerator extends Generator {
-
- /**
- * The console manager.
- *
- * @var \Drupal\Console\Extension\Manager
- */
- protected $extensionManager;
-
- /**
- * The twig renderer.
- *
- * @var \Drupal\Console\Core\Utils\TwigRenderer
- */
- protected $renderer;
.
.
.
...
Expected Behaviour
When using -e
option, I expect Rector to skip the files that are missing, without printing additional errors, but also without applying a code linting rule.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (16 by maintainers)
Looking at option
e
now, it was added to improve working with legacy projects that misses autoloading.Yet, nowadays Rector and PHPStan that we use here 100 % needs classes to be autoloaded, so the
e
option willl be dropped. It only creates false positive bugs that cannot be solve without autoloading. PHPStan has same approach and shows these errors.