rector/ecs.php

112 lines
4.5 KiB
PHP
Raw Normal View History

2020-07-16 13:55:21 +02:00
<?php
2020-07-16 20:59:54 +02:00
declare(strict_types=1);
2020-07-16 13:55:21 +02:00
use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
2020-07-27 08:56:25 +02:00
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
2020-07-16 13:55:21 +02:00
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
2020-07-16 20:59:54 +02:00
use PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer;
use PhpCsFixer\Fixer\ReturnNotation\ReturnAssignmentFixer;
2020-07-16 13:55:21 +02:00
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
2020-08-29 11:03:40 +02:00
use SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff;
2020-07-18 11:24:54 +02:00
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
2020-07-16 20:59:54 +02:00
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
2020-07-16 13:55:21 +02:00
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
2020-07-16 13:55:21 +02:00
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
2020-07-16 20:59:54 +02:00
$services->set(StandaloneLineInMultilineArrayFixer::class);
$services->set(ArrayOpenerAndCloserNewlineFixer::class);
2020-07-20 00:52:12 +02:00
2020-07-16 13:55:21 +02:00
$services->set(GeneralPhpdocAnnotationRemoveFixer::class)
2020-08-03 21:14:41 +02:00
->call('configure', [[
'annotations' => ['throws', 'author', 'package', 'group'],
]]);
2020-07-16 13:55:21 +02:00
$services->set(LineLengthFixer::class);
2020-07-27 08:56:25 +02:00
$services->set(NoSuperfluousPhpdocTagsFixer::class)
->call('configure', [[
'allow_mixed' => true,
]]);
2020-07-16 13:55:21 +02:00
$parameters = $containerConfigurator->parameters();
2020-07-16 20:46:59 +02:00
$parameters->set(Option::PATHS, [
__DIR__ . '/bin',
__DIR__ . '/src',
__DIR__ . '/packages',
__DIR__ . '/rules',
__DIR__ . '/tests',
__DIR__ . '/utils',
__DIR__ . '/compiler',
__DIR__ . '/config',
__DIR__ . '/ecs.php',
2020-07-19 19:54:00 +02:00
__DIR__ . '/rector.php',
2020-07-16 20:46:59 +02:00
__DIR__ . '/rector-ci.php',
2020-07-16 20:59:54 +02:00
__DIR__ . '/config/set',
2020-07-16 20:46:59 +02:00
]);
2020-07-16 13:55:21 +02:00
$parameters->set(Option::SETS, [
SetList::PSR_12,
SetList::PHP_70,
SetList::PHP_71,
SetList::SYMPLIFY,
SetList::COMMON,
SetList::CLEAN_CODE,
]);
2020-07-16 13:55:21 +02:00
2020-07-16 20:46:59 +02:00
$parameters->set(Option::EXCLUDE_PATHS, [
2020-07-16 13:55:21 +02:00
'*/Source/*',
'*/Fixture/*',
'*/Expected/*',
2020-07-16 20:46:59 +02:00
# generated from /vendor
2020-07-16 13:55:21 +02:00
__DIR__ . '/packages/doctrine-annotation-generated/src/ConstantPreservingDocParser.php',
2020-07-16 20:59:54 +02:00
__DIR__ . '/packages/doctrine-annotation-generated/src/ConstantPreservingAnnotationReader.php',
2020-07-28 17:15:30 +02:00
// template files
__DIR__ . '/packages/rector-generator/templates/*',
2020-07-16 13:55:21 +02:00
]);
$parameters->set(Option::SKIP, [
2020-08-29 11:03:40 +02:00
// broken
UnusedVariableSniff::class => null,
2020-07-16 13:55:21 +02:00
GlobalNamespaceImportFixer::class => null,
MethodDeclarationSniff::class . '.Underscore' => null,
2020-07-16 20:59:54 +02:00
PhpdocTypesFixer::class => [__DIR__ . '/rules/php74/src/Rector/Double/RealToFloatTypeCastRector.php'],
2020-07-16 13:55:21 +02:00
CommentedOutCodeSniff::class . '.Found' => [
__DIR__ . '/rules/php72/src/Rector/Assign/ListEachRector.php',
__DIR__ . '/rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php',
2020-07-16 13:55:21 +02:00
__DIR__ . '/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php',
],
PhpUnitStrictFixer::class => [
__DIR__ . '/packages/better-php-doc-parser/tests/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php',
__DIR__ . '/tests/PhpParser/Node/NodeFactoryTest.php',
2020-07-16 20:59:54 +02:00
'*TypeResolverTest.php',
2020-07-16 13:55:21 +02:00
],
UnaryOperatorSpacesFixer::class => null,
// breaks on-purpose annotated variables
ReturnAssignmentFixer::class => null,
// buggy with specific markdown snippet file in docs/rules_overview.md
ArrayListItemNewlineFixer::class => null,
BlankLineAfterOpeningTagFixer::class => null,
2020-08-12 20:30:42 +02:00
StrictComparisonFixer::class => [__DIR__ . '/rules/polyfill/src/ConditionEvaluator.php'],
// bugged for some reason
ArrayIndentationFixer::class => [
__DIR__ . '/rules/order/src/Rector/Class_/OrderPublicInterfaceMethodRector.php',
],
2020-07-16 20:59:54 +02:00
]);
2020-07-16 13:55:21 +02:00
2020-08-18 23:52:31 +02:00
$parameters->set(Option::LINE_ENDING, "\n");
2020-07-16 13:55:21 +02:00
};