-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "--only" option to process only a single rule
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
- Loading branch information
Showing
39 changed files
with
560 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--only "Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e/only-option-quote-double-equalnone/expected-output.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) ../only-option/src/MultiRules.php:9 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
echo 'a statement'; | ||
} | ||
} | ||
- | ||
- private function notUsed() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUnusedPrivateMethodRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/../only-option/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
RemoveAlwaysElseRector::class, | ||
RemoveUnusedPrivateMethodRector::class, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--only='Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPrivateMethodRector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e/only-option-quote-single-bsdouble/expected-output.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) ../only-option/src/MultiRules.php:9 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
echo 'a statement'; | ||
} | ||
} | ||
- | ||
- private function notUsed() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUnusedPrivateMethodRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/../only-option/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
RemoveAlwaysElseRector::class, | ||
RemoveUnusedPrivateMethodRector::class, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--only 'Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e/only-option-quote-single-equalnone/expected-output.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) ../only-option/src/MultiRules.php:9 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
echo 'a statement'; | ||
} | ||
} | ||
- | ||
- private function notUsed() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUnusedPrivateMethodRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/../only-option/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
RemoveAlwaysElseRector::class, | ||
RemoveUnusedPrivateMethodRector::class, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--only='Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) ../only-option/src/MultiRules.php:9 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
echo 'a statement'; | ||
} | ||
} | ||
- | ||
- private function notUsed() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUnusedPrivateMethodRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/../only-option/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
RemoveAlwaysElseRector::class, | ||
RemoveUnusedPrivateMethodRector::class, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--only="Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) src/MultiRules.php:9 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
echo 'a statement'; | ||
} | ||
} | ||
- | ||
- private function notUsed() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUnusedPrivateMethodRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/src', | ||
]); | ||
|
||
$rectorConfig->rules([ | ||
RemoveAlwaysElseRector::class, | ||
RemoveUnusedPrivateMethodRector::class, | ||
]); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
final class MultiRules | ||
{ | ||
public function doSomething() | ||
{ | ||
if (true === false) { | ||
return -1; | ||
} else { | ||
echo 'a statement'; | ||
} | ||
} | ||
|
||
private function notUsed() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class RemoveAlwaysElse | ||
{ | ||
public function run($value) | ||
{ | ||
if ($value) { | ||
throw new \InvalidStateException; | ||
} else { | ||
return 10; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.