Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions resources/docs/run-single-rule.md
Original file line number Diff line number Diff line change
@@ -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`.

<br>

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.
7 changes: 4 additions & 3 deletions src/Documentation/DocumentationMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'),
],
];
}
Expand Down