2020-10-29 09:44:07 +00:00
|
|
|
# How To Ignore Rule or Paths
|
|
|
|
|
2020-12-04 23:22:12 +00:00
|
|
|
## Preferred Way: Config
|
2020-10-29 09:44:07 +00:00
|
|
|
|
|
|
|
```php
|
|
|
|
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
|
2022-04-12 11:52:08 +00:00
|
|
|
use Rector\Config\RectorConfig;
|
2020-10-29 09:44:07 +00:00
|
|
|
|
2022-04-12 11:52:08 +00:00
|
|
|
return static function (RectorConfig $rectorConfig): void {
|
2020-10-29 09:44:07 +00:00
|
|
|
// is there a file you need to skip?
|
2022-04-12 11:52:08 +00:00
|
|
|
$rectorConfig->skip([
|
2020-10-29 09:44:07 +00:00
|
|
|
// single file
|
|
|
|
__DIR__ . '/src/ComplicatedFile.php',
|
|
|
|
// or directory
|
|
|
|
__DIR__ . '/src',
|
|
|
|
// or fnmatch
|
|
|
|
__DIR__ . '/src/*/Tests/*',
|
|
|
|
|
2020-11-26 22:09:21 +00:00
|
|
|
// is there single rule you don't like from a set you use?
|
|
|
|
SimplifyIfReturnBoolRector::class,
|
2020-10-29 09:44:07 +00:00
|
|
|
|
2020-11-26 22:09:21 +00:00
|
|
|
// or just skip rule in specific directory
|
|
|
|
SimplifyIfReturnBoolRector::class => [
|
2020-10-29 09:44:07 +00:00
|
|
|
// single file
|
|
|
|
__DIR__ . '/src/ComplicatedFile.php',
|
|
|
|
// or directory
|
|
|
|
__DIR__ . '/src',
|
|
|
|
// or fnmatch
|
|
|
|
__DIR__ . '/src/*/Tests/*',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
## In a File
|
|
|
|
|
2020-12-04 23:22:12 +00:00
|
|
|
For in-file exclusion, use `@noRector \Rector\SomeClass\NameRector` annotation:
|
2020-10-29 09:44:07 +00:00
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
class SomeClass
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @noRector
|
|
|
|
*/
|
|
|
|
public const NAME = '102';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @noRector
|
|
|
|
*/
|
|
|
|
public function foo(): void
|
|
|
|
{
|
|
|
|
/** @noRector \Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector */
|
|
|
|
round(1 + 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|