Skip to content

[Utils] Add PHPStan rule to spot Rector rules not registered in any set - #8760

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-phpstan-register-rule-wt
Oct 22, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-phpstan-register-rule-wt

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds RegisterRectorRule, a PHPStan rule that flags a Rector rule class that can never run because it is registered in no set or level config.

A non-configurable, non-deprecated Rector rule only runs when some set or level lists its ::class. If none does, the rule is dead code - it ships but nothing can trigger it. This rule enforces that invariant, the same way RegisterRelatedPolyfillRectorRule enforces polyfill-set membership.

Skips:

  • ConfigurableRectorInterface rules - shipped for downstream configs (e.g. rector-laravel) to register, so absence from a rector-src set is expected
  • DeprecatedInterface rules - intentionally unregistered
  • Rector\Tests\ test doubles - wired directly in their test
  • abstract classes

The scan reads config/ and src/Config/ once and checks for the ShortName::class reference.

Two existing standalone rules are opt-in via explicit withRules() only and kept out of any set on purpose; they are listed as ignores in phpstan.neon with a comment, next to the existing rector.upgradeDowngradeRegisteredInSet exceptions.

Note: no non-configurable Transform rule turned out to be orphaned - the unregistered Transform rules are all ConfigurableRectorInterface, so they are downstream opt-in, not dead.

@TomasVotruba
TomasVotruba force-pushed the tv-phpstan-register-rule-wt branch 6 times, most recently from ff69001 to 82224f1 Compare October 22, 2026 18:45
Flags any Rector rule whose ::class is in no set/level config - it can never
run otherwise. Scans rector-src config + src/Config and sibling rector-* configs.
Deprecated rules and Rector\Tests\ doubles are skipped. A short handful of rules
registered only in third-party sets (rector-laravel, drupal-rector, which cannot
be installed here due to the rector/rector replace) or shipped opt-in only are
listed as rector.registerRector ignores.
@TomasVotruba
TomasVotruba force-pushed the tv-phpstan-register-rule-wt branch from 82224f1 to f404e9f Compare October 22, 2026 19:02
@TomasVotruba
TomasVotruba merged commit 411cdf4 into main Oct 22, 2026
63 checks passed
@TomasVotruba
TomasVotruba deleted the tv-phpstan-register-rule-wt branch October 22, 2026 19:40
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