Skip to content

[ax] Allow --only to run several rules at once - #8451

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-only-multiple
Sep 3, 2026
Merged

[ax] Allow --only to run several rules at once#8451
TomasVotruba merged 2 commits into
mainfrom
tv-only-multiple

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

--only accepted a single rule, so applying a curated subset of rules in one run was not possible - you had to run Rector once per rule. Agents and scripts that want to apply a specific set of rules (and nothing else) had no way to express it.

What

--only now accepts multiple values by repeating the flag:

rector process --only=App\Rector\FooRector --only=App\Rector\BarRector

A rule runs if it matches any of the given --only values. A single --only=Foo behaves exactly as before, so this is backward compatible.

Changes

  • --only option is now VALUE_REQUIRED | VALUE_IS_ARRAY.
  • Configuration::getOnlyRule(): ?string -> getOnlyRules(): string[]; each value is resolved through the existing OnlyRuleResolver (short names, ambiguity and not-found errors unchanged, per rule).
  • ConfigurationRuleFilter::filterOnlyRule() -> filterOnlyRules(), keeping any rule that matches one of the listed classes.
  • ChangedFilesDetector::setActiveScope() takes the rule list and builds the per-selection cache key from it, so different --only sets keep separate cache scopes.
  • Parallel: the worker command line mirrors array options generically (one flag per value), which removes a now-redundant special-case block for --only and fixes passing several rules to workers.

Tests

  • ConfigurationRuleFilterTest::testOnlyRulesKeepsEveryListedRule - three rules in, two listed, only those two kept.
  • Existing --only scope/cache tests updated to the array shape; all green.
  • composer check-cs, composer phpstan clean; verified on the CLI in both parallel and single-process runs (two rules -> both applied; one rule -> BC).

…earDown

The new onlyRules test left the shared ConfigurationRuleFilter singleton holding onlyRules, which leaked into other tests in the same process and filtered out their rules. Reset to a neutral Configuration after each test.

Claude-Session: https://claude.ai/code/session_01QDEtmow9psVbccgbgHDqgd
@TomasVotruba
TomasVotruba merged commit 27c5f89 into main Sep 3, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the tv-only-multiple branch September 3, 2026 22:56
@TomasVotruba TomasVotruba changed the title [Console] Allow --only to run several rules at once [ax] Allow --only to run several rules at once Sep 3, 2026
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