mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
add exclude_rectors option
This commit is contained in:
parent
35dd56ee82
commit
7a5f4e7972
11
README.md
11
README.md
@ -73,6 +73,8 @@ parameters:
|
||||
- 'vendor/project-without-composer'
|
||||
```
|
||||
|
||||
## Exclude Paths and Rectors
|
||||
|
||||
You can also **exclude files or directories** (with regex or [fnmatch](http://php.net/manual/en/function.fnmatch.php)):
|
||||
|
||||
```yaml
|
||||
@ -82,6 +84,15 @@ parameters:
|
||||
- '*/src/*/Tests/*'
|
||||
```
|
||||
|
||||
Do you want to use whole set, except that one rule? Exclude it:
|
||||
|
||||
```yaml
|
||||
# rector.yml
|
||||
parameters:
|
||||
exclude_rectors:
|
||||
- 'Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector'
|
||||
```
|
||||
|
||||
## Running Rector
|
||||
|
||||
### A. Prepared Sets
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
final class RemoveExcludedRectorsCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const EXCLUDE_RECTORS_KEY = 'exclude_rectors';
|
||||
|
||||
public function process(ContainerBuilder $containerBuilder): void
|
||||
{
|
||||
$parameterBag = $containerBuilder->getParameterBag();
|
||||
if ($parameterBag->has(self::EXCLUDE_RECTORS_KEY) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$excludedRectors = (array) $parameterBag->get(self::EXCLUDE_RECTORS_KEY);
|
||||
|
||||
foreach ($containerBuilder->getDefinitions() as $id => $definition) {
|
||||
if ($definition->getClass() === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! in_array($definition->getClass(), $excludedRectors, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$containerBuilder->removeDefinition($id);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace Rector\DependencyInjection;
|
||||
|
||||
use Rector\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\DependencyInjection\CompilerPass\RemoveExcludedRectorsCompilerPass;
|
||||
use Rector\DependencyInjection\Loader\TolerantRectorYamlFileLoader;
|
||||
use Rector\FileSystemRector\Contract\FileSystemRectorInterface;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
@ -52,6 +53,8 @@ final class RectorKernel extends Kernel
|
||||
|
||||
protected function build(ContainerBuilder $containerBuilder): void
|
||||
{
|
||||
$containerBuilder->addCompilerPass(new RemoveExcludedRectorsCompilerPass());
|
||||
|
||||
// for defaults
|
||||
$containerBuilder->addCompilerPass(new AutowireSinglyImplementedCompilerPass());
|
||||
$containerBuilder->addCompilerPass(new AutowireArrayParameterCompilerPass());
|
||||
|
@ -1,10 +1,9 @@
|
||||
imports:
|
||||
- { resource: '../../packages/**/src/config/config.yml' }
|
||||
# new config location
|
||||
- { resource: '../../packages/**/config/config.yml' }
|
||||
- { resource: 'services.yml' }
|
||||
- { resource: 'external-services.yml' }
|
||||
|
||||
parameters:
|
||||
exclude_paths: []
|
||||
exclude_rectors: []
|
||||
autoload_paths: []
|
||||
|
@ -35,8 +35,31 @@ services:
|
||||
Symplify\PackageBuilder\EventSubscriber\ParameterTypoProofreaderEventSubscriber: ~
|
||||
Symplify\PackageBuilder\Parameter\ParameterTypoProofreader:
|
||||
$correctToTypos:
|
||||
# keep "exclude_" explicit, to get typos to the correct key
|
||||
exclude_paths:
|
||||
- '#(ex(c)?lude|ignore)((d)?_(path(s)?|dir(s)?|file(s)?))?#'
|
||||
- 'exclude_path'
|
||||
- 'exclude_dir'
|
||||
- 'exclude_dirs'
|
||||
- 'exclude_file'
|
||||
- 'exclude_files'
|
||||
- 'ignore_path'
|
||||
- 'ignore_paths'
|
||||
- 'ignore_dir'
|
||||
- 'ignore_dirs'
|
||||
- 'ignore_file'
|
||||
- 'ignore_files'
|
||||
- 'skip_path'
|
||||
- 'skip_paths'
|
||||
- 'skip_dir'
|
||||
- 'skip_dirs'
|
||||
- 'skip_file'
|
||||
- 'skip_files'
|
||||
exclude_rectors:
|
||||
- 'exclude_rector'
|
||||
- 'excluded_rector'
|
||||
- 'excluded_rectors'
|
||||
- 'skip_rector'
|
||||
- 'skip_rectors'
|
||||
autoload_paths:
|
||||
# https://regex101.com/r/aXEZYk/1
|
||||
- '#(autoload|include|bootstrap)((ed)?_(path(s)?|dir(s)?|file(s)?))?#'
|
||||
|
Loading…
x
Reference in New Issue
Block a user