From f7d844928c20e22ef76a0bf3e34437e13bb8e4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Nov 2020 19:57:12 +0100 Subject: [PATCH 1/2] Enhancement: Assert that deprecated fixers are not enabled --- psalm-baseline.xml | 3 + test/Unit/RuleSet/AbstractRuleSetTestCase.php | 58 ++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a12a980f..6b7801d1 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -11,6 +11,9 @@ getFixers registerBuiltInFixers + + $ruleConfiguration + getRules diff --git a/test/Unit/RuleSet/AbstractRuleSetTestCase.php b/test/Unit/RuleSet/AbstractRuleSetTestCase.php index 4943435f..b37ea108 100644 --- a/test/Unit/RuleSet/AbstractRuleSetTestCase.php +++ b/test/Unit/RuleSet/AbstractRuleSetTestCase.php @@ -168,6 +168,37 @@ final public function testRulesDoNotContainRuleSets(): void )); } + final public function testRulesDoNotEnableDeprecatedFixers(): void + { + $fixers = self::builtInFixers(); + + $rulesEnablingDeprecatedFixers = \array_filter( + self::createRuleSet()->rules(), + static function ($ruleConfiguration, string $ruleName) use ($fixers): bool { + if (false === $ruleConfiguration) { + return false; + } + + if (!\array_key_exists($ruleName, $fixers)) { + return false; + } + + $fixer = $fixers[$ruleName]; + + return $fixer instanceof Fixer\DeprecatedFixerInterface; + }, + \ARRAY_FILTER_USE_BOTH + ); + + $namesOfEnabledDeprecatedFixers = \array_keys($rulesEnablingDeprecatedFixers); + + self::assertEmpty($namesOfEnabledDeprecatedFixers, \sprintf( + "Failed asserting that deprecated fixers with names\n\n%s\n\nare not enabled in rule set \"%s\".", + ' - ' . \implode("\n - ", $namesOfEnabledDeprecatedFixers), + static::className() + )); + } + /** * @phpstan-return class-string * @@ -228,20 +259,33 @@ final protected static function createRuleSet(?string $header = null): Config\Ru } /** - * @return array + * @return array */ - private static function builtInFixerNames(): array + private static function builtInFixers(): array { $fixerFactory = FixerFactory::create(); $fixerFactory->registerBuiltInFixers(); - /** @var array $builtInFixerNames */ - $builtInFixerNames = \array_values(\array_map(static function (Fixer\FixerInterface $fixer): string { - return $fixer->getName(); - }, $fixerFactory->getFixers())); + $fixers = $fixerFactory->getFixers(); + + /** @var array $builtInFixers */ + $builtInFixers = \array_combine( + \array_map(static function (Fixer\FixerInterface $fixer): string { + return $fixer->getName(); + }, $fixers), + $fixers + ); + + return $builtInFixers; + } - return $builtInFixerNames; + /** + * @return array + */ + private static function builtInFixerNames(): array + { + return \array_keys(self::builtInFixers()); } /** From 1c907cb576c69f5577eebf8f1a0df2938cbd42ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Nov 2020 20:03:12 +0100 Subject: [PATCH 2/2] Fix: Enable and configure proxied instead of deprecated fixers --- CHANGELOG.md | 15 +++++++++++++-- src/RuleSet/Laravel6.php | 2 +- src/RuleSet/Php71.php | 8 ++++++-- src/RuleSet/Php73.php | 8 ++++++-- src/RuleSet/Php74.php | 8 ++++++-- test/Unit/RuleSet/Laravel6Test.php | 2 +- test/Unit/RuleSet/Php71Test.php | 8 ++++++-- test/Unit/RuleSet/Php73Test.php | 8 ++++++-- test/Unit/RuleSet/Php74Test.php | 8 ++++++-- 9 files changed, 51 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea9ee10..204a76d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`2.5.1...main`][2.5.1...main]. +For a full diff see [`2.5.2...main`][2.5.2...main]. + +## [`2.5.2`][2.5.2] + +For a full diff see [`2.5.1...2.5.2`][2.5.1...2.5.2]. + +### Fixed + +* Enabled and configured proxied instead of deprecated fixers ([#241]), by [@dependabot] ## [`2.5.1`][2.5.1] @@ -130,6 +138,7 @@ For a full diff see [`d899e77...1.0.0`][d899e77...1.0.0]. [2.4.0]: https://github.com/ergebnis/php-cs-fixer-config/releases/tag/2.4.0 [2.5.0]: https://github.com/ergebnis/php-cs-fixer-config/releases/tag/2.5.0 [2.5.1]: https://github.com/ergebnis/php-cs-fixer-config/releases/tag/2.5.1 +[2.5.2]: https://github.com/ergebnis/php-cs-fixer-config/releases/tag/2.5.2 [d899e77...1.0.0]: https://github.com/ergebnis/php-cs-fixer-config/compare/d899e77...1.0.0 [1.0.0...1.1.0]: https://github.com/ergebnis/php-cs-fixer-config/compare/1.0.0...1.1.0 @@ -145,7 +154,8 @@ For a full diff see [`d899e77...1.0.0`][d899e77...1.0.0]. [2.3.0...2.4.0]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.3.0...2.4.0 [2.4.0...2.5.0]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.4.0...2.5.0 [2.5.0...2.5.1]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.5.0...2.5.1 -[2.5.1...main]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.5.1...main +[2.5.1...2.5.2]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.5.1...2.5.2 +[2.5.2...main]: https://github.com/ergebnis/php-cs-fixer-config/compare/2.5.2...main [#3]: https://github.com/ergebnis/php-cs-fixer-config/pull/3 [#14]: https://github.com/ergebnis/php-cs-fixer-config/pull/14 @@ -160,6 +170,7 @@ For a full diff see [`d899e77...1.0.0`][d899e77...1.0.0]. [#215]: https://github.com/ergebnis/php-cs-fixer-config/pull/215 [#220]: https://github.com/ergebnis/php-cs-fixer-config/pull/220 [#226]: https://github.com/ergebnis/php-cs-fixer-config/pull/226 +[#241]: https://github.com/ergebnis/php-cs-fixer-config/pull/241 [@dependabot]: https://github.com/apps/dependabot [@linuxjuggler]: https://github.com/linuxjuggler diff --git a/src/RuleSet/Laravel6.php b/src/RuleSet/Laravel6.php index ef2caa48..f1193aa2 100644 --- a/src/RuleSet/Laravel6.php +++ b/src/RuleSet/Laravel6.php @@ -101,7 +101,7 @@ final class Laravel6 extends AbstractRuleSet 'list_syntax' => false, 'logical_operators' => false, 'lowercase_cast' => true, - 'lowercase_constants' => true, + 'lowercase_constants' => false, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, // added from Symfony 'magic_constant_casing' => true, diff --git a/src/RuleSet/Php71.php b/src/RuleSet/Php71.php index 139f3488..0dd8ac63 100644 --- a/src/RuleSet/Php71.php +++ b/src/RuleSet/Php71.php @@ -121,7 +121,7 @@ final class Php71 extends AbstractRuleSet 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => false, 'heredoc_to_nowdoc' => true, @@ -337,7 +337,11 @@ final class Php71 extends AbstractRuleSet ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true, diff --git a/src/RuleSet/Php73.php b/src/RuleSet/Php73.php index b6e2b2ae..54f41257 100644 --- a/src/RuleSet/Php73.php +++ b/src/RuleSet/Php73.php @@ -121,7 +121,7 @@ final class Php73 extends AbstractRuleSet 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => true, 'heredoc_to_nowdoc' => true, @@ -337,7 +337,11 @@ final class Php73 extends AbstractRuleSet ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true, diff --git a/src/RuleSet/Php74.php b/src/RuleSet/Php74.php index 2a5e7573..ff27cde0 100644 --- a/src/RuleSet/Php74.php +++ b/src/RuleSet/Php74.php @@ -121,7 +121,7 @@ final class Php74 extends AbstractRuleSet 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => true, 'heredoc_to_nowdoc' => true, @@ -337,7 +337,11 @@ final class Php74 extends AbstractRuleSet ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true, diff --git a/test/Unit/RuleSet/Laravel6Test.php b/test/Unit/RuleSet/Laravel6Test.php index c266de65..ba50878e 100644 --- a/test/Unit/RuleSet/Laravel6Test.php +++ b/test/Unit/RuleSet/Laravel6Test.php @@ -104,7 +104,7 @@ final class Laravel6Test extends AbstractRuleSetTestCase 'list_syntax' => false, 'logical_operators' => false, 'lowercase_cast' => true, - 'lowercase_constants' => true, + 'lowercase_constants' => false, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, // added from Symfony 'magic_constant_casing' => true, diff --git a/test/Unit/RuleSet/Php71Test.php b/test/Unit/RuleSet/Php71Test.php index 32de6a51..53711451 100644 --- a/test/Unit/RuleSet/Php71Test.php +++ b/test/Unit/RuleSet/Php71Test.php @@ -127,7 +127,7 @@ final class Php71Test extends AbstractRuleSetTestCase 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => false, 'heredoc_to_nowdoc' => true, @@ -343,7 +343,11 @@ final class Php71Test extends AbstractRuleSetTestCase ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true, diff --git a/test/Unit/RuleSet/Php73Test.php b/test/Unit/RuleSet/Php73Test.php index e41e1300..a9b6b8f3 100644 --- a/test/Unit/RuleSet/Php73Test.php +++ b/test/Unit/RuleSet/Php73Test.php @@ -127,7 +127,7 @@ final class Php73Test extends AbstractRuleSetTestCase 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => true, 'heredoc_to_nowdoc' => true, @@ -343,7 +343,11 @@ final class Php73Test extends AbstractRuleSetTestCase ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true, diff --git a/test/Unit/RuleSet/Php74Test.php b/test/Unit/RuleSet/Php74Test.php index 71f2a2b5..6c2126b6 100644 --- a/test/Unit/RuleSet/Php74Test.php +++ b/test/Unit/RuleSet/Php74Test.php @@ -127,7 +127,7 @@ final class Php74Test extends AbstractRuleSetTestCase 'function_typehint_space' => true, 'general_phpdoc_annotation_remove' => false, 'global_namespace_import' => false, - 'hash_to_slash_comment' => true, + 'hash_to_slash_comment' => false, 'header_comment' => false, 'heredoc_indentation' => true, 'heredoc_to_nowdoc' => true, @@ -343,7 +343,11 @@ final class Php74Test extends AbstractRuleSetTestCase ], 'single_import_per_statement' => true, 'single_line_after_imports' => true, - 'single_line_comment_style' => false, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'hash', + ], + ], 'single_line_throw' => false, 'single_quote' => true, 'single_trait_insert_per_statement' => true,