update ecs and rector config

This commit is contained in:
lubiana 2022-05-19 23:35:10 +02:00 committed by Andre Lubian
parent 997d160796
commit 6818179857

View file

@ -148,17 +148,12 @@ use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff; use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff; use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList; use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ECSConfig $config): void { return static function (ECSConfig $config): void {
$parameters = $config->parameters(); $config->parallel();
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/ecs.php']); $config->paths([__DIR__ . '/src', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']);
$parameters->set(Option::PARALLEL, true); $config->skip([BlankLineAfterOpeningTagFixer::class, OrderedImportsFixer::class, NewWithBracesFixer::class]);
$parameters->set(
Option::SKIP,
[BlankLineAfterOpeningTagFixer::class, OrderedImportsFixer::class, NewWithBracesFixer::class]
);
$config->sets([ $config->sets([
SetList::PSR_12, SetList::PSR_12,
@ -174,53 +169,59 @@ return static function (ECSConfig $config): void {
SetList::CONTROL_STRUCTURES, SetList::CONTROL_STRUCTURES,
]); ]);
$services = $config->services();
// force visibility declaration on class constants // force visibility declaration on class constants
$services->set(ClassConstantVisibilitySniff::class) $config->ruleWithConfiguration(ClassConstantVisibilitySniff::class, [
->property('fixable', true); 'fixable' => true,
]);
// sort all use statements // sort all use statements
$services->set(AlphabeticallySortedUsesSniff::class); $config->rules([
$services->set(DisallowGroupUseSniff::class); AlphabeticallySortedUsesSniff::class,
$services->set(MultipleUsesPerLineSniff::class); DisallowGroupUseSniff::class,
$services->set(NamespaceSpacingSniff::class); MultipleUsesPerLineSniff::class,
NamespaceSpacingSniff::class,
]);
// import all namespaces, and event php core functions and classes // import all namespaces, and even php core functions and classes
$services->set(ReferenceUsedNamesOnlySniff::class) $config->ruleWithConfiguration(
->property('allowFallbackGlobalConstants', false) ReferenceUsedNamesOnlySniff::class,
->property('allowFallbackGlobalFunctions', false) [
->property('allowFullyQualifiedGlobalClasses', false) 'allowFallbackGlobalConstants' => false,
->property('allowFullyQualifiedGlobalConstants', false) 'allowFallbackGlobalFunctions' => false,
->property('allowFullyQualifiedGlobalFunctions', false) 'allowFullyQualifiedGlobalClasses' => false,
->property('allowFullyQualifiedNameForCollidingClasses', true) 'allowFullyQualifiedGlobalConstants' => false,
->property('allowFullyQualifiedNameForCollidingConstants', true) 'allowFullyQualifiedGlobalFunctions' => false,
->property('allowFullyQualifiedNameForCollidingFunctions', true) 'allowFullyQualifiedNameForCollidingClasses' => true,
->property('searchAnnotations', true) 'allowFullyQualifiedNameForCollidingConstants' => true,
->property('fixable', true); 'allowFullyQualifiedNameForCollidingFunctions' => true,
'searchAnnotations' => true,
]
);
// define newlines between use statements // define newlines between use statements
$services->set(UseSpacingSniff::class) $config->ruleWithConfiguration(UseSpacingSniff::class, [
->property('linesCountBeforeFirstUse', 1) 'linesCountBeforeFirstUse' => 1,
->property('linesCountBetweenUseTypes', 1) 'linesCountBetweenUseTypes' => 1,
->property('linesCountAfterLastUse', 1); 'linesCountAfterLastUse' => 1,
]);
// strict types declaration should be on same line as opening tag // strict types declaration should be on same line as opening tag
$services->set(DeclareStrictTypesSniff::class) $config->ruleWithConfiguration(DeclareStrictTypesSniff::class, [
->property('declareOnFirstLine', true) 'declareOnFirstLine' => true,
->property('spacesCountAroundEqualsSign', 0); 'spacesCountAroundEqualsSign' => 0,
]);
// disallow ?Foo typehint in favor of Foo|null // disallow ?Foo typehint in favor of Foo|null
$services->set(UnionTypeHintFormatSniff::class) $config->ruleWithConfiguration(UnionTypeHintFormatSniff::class, [
->property('withSpaces', 'no') 'withSpaces' => 'no',
->property('shortNullable', 'no') 'shortNullable' => 'no',
->property('nullPosition', 'last'); 'nullPosition' => 'last',
]);
// Remove useless parantheses in new statements // Remove useless parentheses in new statements
$services->set(NewWithoutParenthesesSniff::class); $config->rule(NewWithoutParenthesesSniff::class);
}; };
``` ```
You can now use `./vendor/bin/ecs` to list all violations of the defined standard and `./vendor/bin/ecs --fix` to You can now use `./vendor/bin/ecs` to list all violations of the defined standard and `./vendor/bin/ecs --fix` to
automatically fix them. automatically fix them.
@ -240,7 +241,7 @@ use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void { return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/config']); $rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/rector.php', __DIR__ . '/ecs.php']);
$rectorConfig->importNames(); $rectorConfig->importNames();