Skip to content

[Configuration] Resolve --only rule name with shell-eaten backslashes - #8267

Merged
TomasVotruba merged 1 commit into
mainfrom
resolve-shell-eaten-backslashes
Aug 2, 2026
Merged

[Configuration] Resolve --only rule name with shell-eaten backslashes#8267
TomasVotruba merged 1 commit into
mainfrom
resolve-shell-eaten-backslashes

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Running this in a shell fails, because zsh/bash strip the unescaped backslashes before Rector ever sees the argument:

bin/rector p --only \Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
In OnlyRuleResolver.php line 61:

  Rule "RectorCodeQualityRectorFuncCallChangeArrayPushToArrayAssignRector" 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"

The rule name is correct, only the separators are gone. This adds a last-resort fallback: when the passed name contains no backslash at all, compare it against registered rules with their backslashes stripped. If exactly one matches, use it.

-$ bin/rector p --only \Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
-  Rule "RectorCodeQualityRectorFuncCallChangeArrayPushToArrayAssignRector" was not found.
+$ bin/rector p --only \Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
+  [OK] Rector is done!

Ambiguous or unknown flattened names still throw the same errors as before.

@TomasVotruba
TomasVotruba merged commit ec55677 into main Aug 2, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the resolve-shell-eaten-backslashes branch August 2, 2026 22:00
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