rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.74k stars 687 forks source link

Command line option to execute a single rule only #8899

Open cweiske opened 2 days ago

cweiske commented 2 days ago

Feature Request

It should be possible to provide a command line option that causes rector to apply a single rule only. Configuration file adjustments should not be necessary.

This is a feature needed for #8898 (automatically splitting up rector fixes into different commits).

History

rector once had such a parameter:

Problems

https://github.com/rectorphp/rector/issues/7366#issuecomment-1213551076:

Hi, we actually had this feature few years ago. It was breaking very often as the rules discovery by short class name requires full autoload of all classes. Also you have to make sure there are no 2 short classes. Due to that design, it caused more confusion than value, so we removed it.

https://github.com/rectorphp/rector/issues/3342#issuecomment-734404750:

Since the summer switch from YAML to PHP configs, the set optoins was also redisigned to be used purely in PHP. The set names from CLI were mismatched to their PHP names. The --set option CLI has been removed as well, so the config would be the single place to use

https://github.com/rectorphp/rector/issues/3342#issuecomment-626539791

the --only="Namespace\Class" must be quoted right - slashes? single? double? + OS differences

Maybe we can extend the api to include this backslash, slash, single, double... and reduce complexity.

https://github.com/rectorphp/rector/issues/4699#issue-751723436

After this year's switch from YAML to PHP configs, and dropping --set CLI option to make use of the PHP configs, this feature is contradictory towards PHP autocomplete filosophy

Naming

--only (--rule was renamed to --only in #2655).

Accepted values

The option should accept a single value only: A fully qualified class name (not a short/relative one, see #7366).

./vendor/bin/rector --rule="Rector\Php73\Rector\BooleanOr\IsCountableRector"

Things to consider:

Affected commands


:exclamation: After reading the comments in the previous issues and patches, I have no idea what requirements regarding naming, functionality and stability you have for this feature.

TomasVotruba commented 2 days ago

Thanks for great summary. I think now I'm open to accept this feature, under 2 requirements:

If the feature is user-friendly, let's go :+1: