diff --git a/README.md b/README.md index abdca1b477d..4cc071113e2 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,18 @@ parameters: php_version_features: '7.2' # your version is 7.3 ``` +### Paths + +If you're annoyed by repeating paths in arguments, you can move them to config instead: + +```yaml +# rector.yaml +parameters: + paths: + - 'src' + - 'tests' +``` + ### Import Use Statements FQN classes are imported by default every time Rector performs a change, so you don't have to do it manually/after each run. You can disable it by: diff --git a/composer.json b/composer.json index 1fa2f0d77f2..79073a9dbee 100644 --- a/composer.json +++ b/composer.json @@ -200,7 +200,7 @@ "bin/rector dump-rectors -o markdown > docs/AllRectorsOverview.md", "bin/rector dump-nodes -o markdown > docs/NodesOverview.md" ], - "rector": "bin/rector process packages src tests --config rector-ci.yaml --dry-run" + "rector": "bin/rector process --config rector-ci.yaml --dry-run" }, "scripts-descriptions": { "docs": "Regenerate descriptions of all Rectors to docs/AllRectorsOverview.md file" diff --git a/config/config.yaml b/config/config.yaml index 67928553157..36dc626b37d 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -5,6 +5,8 @@ imports: - { resource: '../utils/**/config/config.yaml', ignore_errors: true } parameters: + # processed paths + paths: [] exclude_paths: [] exclude_rectors: [] autoload_paths: [] @@ -16,6 +18,8 @@ parameters: # e.g. /** @var \Some\ClassHere */ import_doc_blocks: true - php_version_features: ~ # what PHP version should be used for features, local PHP version is used by default + # what PHP version is used for features, composer.json version, then local PHP version is used by default + php_version_features: ~ + file_extensions: - 'php' diff --git a/rector-ci.yaml b/rector-ci.yaml index 5258d68d055..57c537c26c2 100644 --- a/rector-ci.yaml +++ b/rector-ci.yaml @@ -5,6 +5,11 @@ parameters: - 'dead-code' - 'nette-utils-code-quality' + paths: + - 'src' + - 'packages' + - 'tests' + exclude_paths: - '/Fixture/' - '/Source/' diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 736f2d69373..ef73219de87 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -81,6 +81,12 @@ final class ProcessCommand extends AbstractCommand private $stubLoader; /** + * @var string[] + */ + private $paths = []; + + /** + * @param string[] $paths * @param string[] $fileExtensions */ public function __construct( @@ -94,6 +100,7 @@ final class ProcessCommand extends AbstractCommand ReportingExtensionRunner $reportingExtensionRunner, RectorNodeTraverser $rectorNodeTraverser, StubLoader $stubLoader, + array $paths, array $fileExtensions ) { $this->filesFinder = $phpFilesFinder; @@ -109,6 +116,7 @@ final class ProcessCommand extends AbstractCommand $this->stubLoader = $stubLoader; parent::__construct(); + $this->paths = $paths; } protected function configure(): void @@ -117,7 +125,7 @@ final class ProcessCommand extends AbstractCommand $this->setDescription('Upgrade or refactor source code with provided rectors'); $this->addArgument( Option::SOURCE, - InputArgument::REQUIRED | InputArgument::IS_ARRAY, + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Files or directories to be upgraded.' ); $this->addOption( @@ -160,7 +168,7 @@ final class ProcessCommand extends AbstractCommand $this->rectorGuard->ensureSomeRectorsAreRegistered(); $this->stubLoader->loadStubs(); - $source = (array) $input->getArgument(Option::SOURCE); + $source = $this->resolvesSourcePaths($input); $phpFileInfos = $this->filesFinder->findInDirectoriesAndFiles($source, $this->fileExtensions); @@ -187,4 +195,20 @@ final class ProcessCommand extends AbstractCommand return Shell::CODE_SUCCESS; } + + /** + * @return string[] + */ + private function resolvesSourcePaths(InputInterface $input): array + { + $commandLinePaths = (array) $input->getArgument(Option::SOURCE); + + // manual command line value has priority + if (count($commandLinePaths) > 0) { + return $commandLinePaths; + } + + // fallback to config defined paths + return $this->paths; + } }