Skip to content

[Configuration] Report explicit error when --only rule exists but is not registered - #8300

Merged
TomasVotruba merged 2 commits into
mainfrom
only-rule-not-registered-message
Aug 5, 2026
Merged

[Configuration] Report explicit error when --only rule exists but is not registered#8300
TomasVotruba merged 2 commits into
mainfrom
only-rule-not-registered-message

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

--only SomeRule reported "was not found" even when the rule class exists in the autoloaded code and is only missing from rector.php. Now the rule class is looked up (FQCN via ReflectionProvider, short name via a scan of Rector PSR-4 dirs) and the error says so explicitly.

Before:

Rule "SafeDeclareStrictTypesRector" was not found.
The rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only="My\Rector\Rule"

After:

Rule "Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector" exists, but is not registered in your Rector config.
Register it in your rector.php:

    ->withRules([SafeDeclareStrictTypesRector::class])

Unknown rule names keep the original messages.

…not registered

Instead of "was not found", tell the rule class exists and how to register it.
Drop the PSR-4 filesystem scan for short rule names; resolve only fully
qualified class names via ReflectionProvider.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 5, 2026 22:25
@TomasVotruba
TomasVotruba merged commit 63c657c into main Aug 5, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the only-rule-not-registered-message branch August 5, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant