From e7d822fe0c0bc099550c1bd429de393d350a356e Mon Sep 17 00:00:00 2001 From: Krzysztof Rewak Date: Fri, 19 May 2023 07:57:43 +0200 Subject: [PATCH] #91 - ordering and grouping imports (#92) * #91 - ordering and grouping imports * #91 - dependencies update * #91 - reordering --- composer.json | 4 +-- src/Configuration/Defaults/CommonRules.php | 9 ++++--- tests/codestyle/CodestyleTest.php | 1 + .../fixtures/importsOrder/actual.php | 26 ++++++++++++++++++ .../fixtures/importsOrder/expected.php | 27 +++++++++++++++++++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tests/codestyle/fixtures/importsOrder/actual.php create mode 100644 tests/codestyle/fixtures/importsOrder/expected.php diff --git a/composer.json b/composer.json index 93bbbef..4cab17a 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "type": "library", "require": { "php": "^8.1", - "friendsofphp/php-cs-fixer": "^3.15", - "kubawerlos/php-cs-fixer-custom-fixers": "^3.13" + "friendsofphp/php-cs-fixer": "^3.16", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.14" }, "require-dev": { "jetbrains/phpstorm-attributes": "^1.0", diff --git a/src/Configuration/Defaults/CommonRules.php b/src/Configuration/Defaults/CommonRules.php index e77de2d..e3994df 100644 --- a/src/Configuration/Defaults/CommonRules.php +++ b/src/Configuration/Defaults/CommonRules.php @@ -10,7 +10,6 @@ use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer; use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer; use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer; -use PhpCsFixer\Fixer\Basic\BracesFixer; use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; use PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer; use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer; @@ -93,6 +92,7 @@ use PhpCsFixer\Fixer\Strict\StrictParamFixer; use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer; use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer; +use PhpCsFixer\Fixer\Whitespace\BlankLineBetweenImportGroupsFixer; use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer; use PhpCsFixer\Fixer\Whitespace\LineEndingFixer; use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; @@ -198,7 +198,10 @@ class CommonRules extends Rules VoidReturnFixer::class => true, UseArrowFunctionsFixer::class => true, FullyQualifiedStrictTypesFixer::class => true, - OrderedImportsFixer::class => true, + OrderedImportsFixer::class => [ + "sort_algorithm" => "alpha", + "imports_order" => ["class", "function", "const"], + ], PhpdocLineSpanFixer::class => [ "const" => "single", "property" => "single", @@ -272,7 +275,6 @@ class CommonRules extends Rules PhpdocNoIncorrectVarAnnotationFixer::class => true, PhpdocNoSuperfluousParamFixer::class => true, PhpdocParamOrderFixer::class => true, - BracesFixer::class => true, NoSpacesInsideParenthesisFixer::class => true, YodaStyleFixer::class => [ "equal" => false, @@ -301,5 +303,6 @@ class CommonRules extends Rules MultilineWhitespaceBeforeSemicolonsFixer::class => true, LineEndingFixer::class => true, StatementIndentationFixer::class => true, + BlankLineBetweenImportGroupsFixer::class => true, ]; } diff --git a/tests/codestyle/CodestyleTest.php b/tests/codestyle/CodestyleTest.php index ce63666..5551b0e 100644 --- a/tests/codestyle/CodestyleTest.php +++ b/tests/codestyle/CodestyleTest.php @@ -69,6 +69,7 @@ public static function providePhp80Fixtures(): array ["anonymousFunctions"], ["namespaces"], ["emptyLines"], + ["importsOrder"], ]; } diff --git a/tests/codestyle/fixtures/importsOrder/actual.php b/tests/codestyle/fixtures/importsOrder/actual.php new file mode 100644 index 0000000..900801f --- /dev/null +++ b/tests/codestyle/fixtures/importsOrder/actual.php @@ -0,0 +1,26 @@ +merge($merge, new Api(), flag: CONSTANT); + + assert($result); + } +} diff --git a/tests/codestyle/fixtures/importsOrder/expected.php b/tests/codestyle/fixtures/importsOrder/expected.php new file mode 100644 index 0000000..d91c724 --- /dev/null +++ b/tests/codestyle/fixtures/importsOrder/expected.php @@ -0,0 +1,27 @@ +merge($merge, new Api(), flag: CONSTANT); + + assert($result); + } +}