From 1827fd3cee23d2aa3b42bf76027c91f0ae2e72cf Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 29 Apr 2025 22:09:39 +0200 Subject: [PATCH] [docs] add --only option --- resources/docs/run-single-rule.md | 17 +++++++++++++++++ src/Documentation/DocumentationMenuFactory.php | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 resources/docs/run-single-rule.md diff --git a/resources/docs/run-single-rule.md b/resources/docs/run-single-rule.md new file mode 100644 index 000000000..e7960e619 --- /dev/null +++ b/resources/docs/run-single-rule.md @@ -0,0 +1,17 @@ +Sometimes, we want to apply just one rule at a time. But modifying `rector.php` config over and over again is tedious and can lead to mistakes. + +To run single rule, we can use `--only` CLI option. Just add quoted class name: + +```bash +vendor/bin/rector --only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector" +``` + +Mind the quotes, as both Win and *nix system require them to pick up the full class name string (both single and double are supported). + +## Rule must be registered in `rector.php` + +We can run only the rules explicitly registered in `rector.php` or loaded sets. This way configured rules load explicit configuration the same way we would run the rule by calling `vendor/bin/rector`. + +
+ +In case Rector is not able to pick up your class name, see [feature pull-request](https://github.com/rectorphp/rector-src/pull/6441#issuecomment-2497474323) that describes all supported formats. diff --git a/src/Documentation/DocumentationMenuFactory.php b/src/Documentation/DocumentationMenuFactory.php index 998fa557b..5ddc6e8d5 100644 --- a/src/Documentation/DocumentationMenuFactory.php +++ b/src/Documentation/DocumentationMenuFactory.php @@ -23,13 +23,14 @@ public function create(): array { return [ 'First Steps' => [ - $this->documentationMenuItemFactory->createSection('integration-to-new-project', 'New Project', true), + $this->documentationMenuItemFactory->createSection('integration-to-new-project', 'New Project'), $this->documentationMenuItemFactory->createSection('define-paths', 'Define Paths'), $this->documentationMenuItemFactory->createSection('set-lists', 'Set Lists'), - $this->documentationMenuItemFactory->createSection('levels', 'Levels', true), + $this->documentationMenuItemFactory->createSection('levels', 'Levels'), $this->documentationMenuItemFactory->createSection('attributes', 'PHP 8.0 Attributes', true), $this->documentationMenuItemFactory->createSection('composer-based-sets', 'Composer-Based Sets', true), $this->documentationMenuItemFactory->createInternalLink(FindRuleController::class, 'Find Rules'), + $this->documentationMenuItemFactory->createSection('run-single-rule', 'Run single rule', true), $this->documentationMenuItemFactory->createSection( 'ignoring-rules-or-paths', 'Ignoring Rules or Paths' @@ -69,7 +70,7 @@ public function create(): array ), $this->documentationMenuItemFactory->createSection('rules-overview', 'Rules Overview'), $this->documentationMenuItemFactory->createSection('creating-a-node-visitor', 'Creating Node Visitor'), - $this->documentationMenuItemFactory->createSection('how-to-run-on-php-53', 'Run on PHP 5.3', true), + $this->documentationMenuItemFactory->createSection('how-to-run-on-php-53', 'Run on PHP 5.3'), ], ]; }