Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "--only" option to process only a single rule #6441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cweiske
Copy link

@cweiske cweiske commented Nov 15, 2024

The option for the "process" and "list-rules" commands applies the single given rule only, without needing to modify the configuration file.

The option value must be a fully classified class name:

  --only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector"

A hint is given when the user forgot to escape the backslashes.


It is impossible to modify the injected "$rectors" after the command line configuration is parsed, so I had to introduce the ConfigurationRuleFilter singleton.

Since both ListRulesCommand and ProcessCommand make use of the ConfigurationRuleFilter - but list-rules does not have a Configuration - I had to make the filterOnlyRule() method public to prevent code duplication.

Resolves rectorphp/rector#8899


Test it:

./bin/rector process --config=e2e/applied-rule-return-array-nodes/rector.php --dry-run --only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector"

./bin/rector list-rules --config=e2e/applied-rule-return-array-nodes/rector.php --only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector"

The option for the "process" and "list-rules" commands applies
the single given rule only, without needing to modify
the configuration file.

The option value must be a fully classified class name:

  --only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector"

A hint is given when the user forgot to escape the backslashes.

----

It is impossible to modify the injected "$rectors" after the
command line configuration is parsed, so I had to introduce the
ConfigurationRuleFilter singleton.

Since both ListRulesCommand and ProcessCommand make use of the
ConfigurationRuleFilter - but list-rules does not have a Configuration -
I had to make the filterOnlyRule() method public to prevent
code duplication.

Resolves rectorphp/rector#8899
@TomasVotruba
Copy link
Member

TomasVotruba commented Nov 15, 2024

There should be kind of e2e tests that passes and that fails if data are incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command line option to execute a single rule only
2 participants