forked from bonny/WordPress-Simple-History
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rector.php
87 lines (80 loc) · 3.4 KB
/
rector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\Assign\NullCoalescingOperatorRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
return static function ( RectorConfig $rectorConfig ): void {
$rectorConfig->paths(
array(
__DIR__,
)
);
$rectorConfig->phpVersion( PhpVersion::PHP_74 );
// register a single rule
// $rectorConfig->rule( InlineConstructorDefaultToPropertyRector::class );.
// Skip some paths and skip some tests.
$rectorConfig->skip(
array(
__DIR__ . '/tests',
__DIR__ . '/build',
__DIR__ . '/vendor',
__DIR__ . '/node_modules',
__DIR__ . '/rector.php',
// Disable rule because I like to concat my strings.
SimplifyUselessVariableRector::class,
// Doesn't feel WordPress'ish.
CallableThisArrayToAnonymousFunctionRector::class,
// Makes to code more difficult to read.
SimplifyIfReturnBoolRector::class,
// Need to find out what they do.
RenameFunctionRector::class,
JsonThrowOnErrorRector::class,
// I think `count($array) > 0;` is more readable than `$array !== [];`.
CountArrayToEmptyArrayComparisonRector::class,
// I prefer `if ( empty( $post_ids ) ) ` over `if ( $post_ids === [] )`. Also WordPress does not use short arrays.
SimplifyEmptyCheckOnEmptyArrayRector::class,
DisallowedEmptyRuleFixerRector::class,
IssetOnPropertyObjectToPropertyExistsRector::class,
// WordPress uses long arrays.
LongArrayToShortArrayRector::class,
// Prefer `foreach $key => $value` over `foreach (array_keys($values) as $key) {`.
UnusedForeachValueToArrayKeysRector::class,
ReturnTypeFromStrictTypedCallRector::class,
// ReturnTypeFromStrictScalarReturnExprRector::class,
// Ternary not allowed in WP.
SimplifyIfElseToTernaryRector::class,
NullCoalescingOperatorRector::class,
)
);
// define sets of rules
// - https://github.com/rectorphp/rector-src/blob/main/packages/Set/ValueObject/SetList.php
// - https://github.com/rectorphp/rector-src/blob/main/rector.php
// - https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md.
$rectorConfig->sets(
array(
LevelSetList::UP_TO_PHP_74,
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
// Add lists one by one to make diffs not to big.
// SetList::CODING_STYLE,
// SetList::EARLY_RETURN,.
)
);
};