From 3b3afbb8f9635dfaebf34ee62b7efd9d979bb04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 26 Dec 2020 15:50:17 +0100 Subject: [PATCH] Fix: Only require implementations of ExplicitRuleSet to configure every non-deprecated rule --- CHANGELOG.md | 2 ++ src/RuleSet/ExplicitRuleSet.php | 1 + test/Unit/RuleSet/AbstractRuleSetTestCase.php | 26 +----------------- test/Unit/RuleSet/ExplicitRuleSetTestCase.php | 27 +++++++++++++++++++ 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index accc8fa4..47eaa32e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ For a full diff see [`2.9.0...2.10.0`][2.9.0...2.10.0]. * Required only implementations of `Config\RuleSet\ExplicitRuleSet` not to configure any rules for rule sets ([#313]), by [@localheinz] * Required implementations of `Config\RuleSet\ExplicitRuleSet` to configure non-deprecated rules that are configurable with an explicit configuration when enabled ([#314]), by [@localheinz] * Required implementations of `Config\RuleSet\ExplicitRuleSet` to configure non-deprecated rules that are configurable with all non-deprecated configuration options when enabled ([#320]), by [@localheinz] +* Required only implementations of `Config\RuleSet\ExplicitRuleSet` to configure all non-deprecated rules ([#321]), by [@localheinz] ### Fixed @@ -319,6 +320,7 @@ For a full diff see [`d899e77...1.0.0`][d899e77...1.0.0]. [#314]: https://github.com/ergebnis/php-cs-fixer-config/pull/314 [#319]: https://github.com/ergebnis/php-cs-fixer-config/pull/319 [#320]: https://github.com/ergebnis/php-cs-fixer-config/pull/320 +[#321]: https://github.com/ergebnis/php-cs-fixer-config/pull/321 [@dependabot]: https://github.com/apps/dependabot [@linuxjuggler]: https://github.com/linuxjuggler diff --git a/src/RuleSet/ExplicitRuleSet.php b/src/RuleSet/ExplicitRuleSet.php index 26521c8d..aa7a90ee 100644 --- a/src/RuleSet/ExplicitRuleSet.php +++ b/src/RuleSet/ExplicitRuleSet.php @@ -20,6 +20,7 @@ * * - does not configure any rules for rule sets (@see https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.17.3/doc/ruleSets/index.rst) * - configures a rule that can be configured with an explicit configuration when the rule is enabled + * - configures every rule that is not deprecated */ interface ExplicitRuleSet { diff --git a/test/Unit/RuleSet/AbstractRuleSetTestCase.php b/test/Unit/RuleSet/AbstractRuleSetTestCase.php index d8b12667..e2c2faca 100644 --- a/test/Unit/RuleSet/AbstractRuleSetTestCase.php +++ b/test/Unit/RuleSet/AbstractRuleSetTestCase.php @@ -77,20 +77,6 @@ final public function testRuleSetDoesNotConfigureRulesThatAreDeprecated(): void )); } - final public function testRuleSetConfiguresAllRulesThatAreNotDeprecated(): void - { - $namesOfRulesThatAreNotDeprecatedAndNotConfigured = \array_diff( - self::namesOfRulesThatAreBuiltInAndNotDeprecated(), - self::namesOfRulesThatAreConfigured() - ); - - self::assertEmpty($namesOfRulesThatAreNotDeprecatedAndNotConfigured, \sprintf( - "Failed asserting that rule set \"%s\" configures all non-deprecated fixers. Rules with the names\n\n%s\n\nare not configured.", - static::className(), - ' - ' . \implode("\n - ", $namesOfRulesThatAreNotDeprecatedAndNotConfigured) - )); - } - final public function testRuleSetDoesNotConfigureRulesUsingDeprecatedConfigurationOptions(): void { $rules = self::createRuleSet()->rules(); @@ -320,7 +306,7 @@ final protected static function sort(array $data): array /** * @return array */ - private static function namesOfRulesThatAreConfigured(): array + final protected static function namesOfRulesThatAreConfigured(): array { /** * RuleSet\RuleSet::resolveSet() removes disabled fixers, to let's just enable them to make sure they are not removed. @@ -358,14 +344,4 @@ private static function namesOfRulesThatAreBuiltInAndDeprecated(): array return $fixer instanceof Fixer\DeprecatedFixerInterface; })); } - - /** - * @return array - */ - private static function namesOfRulesThatAreBuiltInAndNotDeprecated(): array - { - return \array_keys(\array_filter(self::fixersThatAreBuiltIn(), static function (Fixer\FixerInterface $fixer): bool { - return !$fixer instanceof Fixer\DeprecatedFixerInterface; - })); - } } diff --git a/test/Unit/RuleSet/ExplicitRuleSetTestCase.php b/test/Unit/RuleSet/ExplicitRuleSetTestCase.php index 0ace61fd..1c997d96 100644 --- a/test/Unit/RuleSet/ExplicitRuleSetTestCase.php +++ b/test/Unit/RuleSet/ExplicitRuleSetTestCase.php @@ -44,6 +44,20 @@ final public function testRuleSetDoesNotConfigureRuleSets(): void )); } + final public function testRuleSetConfiguresAllRulesThatAreNotDeprecated(): void + { + $namesOfRulesThatAreNotDeprecatedAndNotConfigured = \array_diff( + self::namesOfRulesThatAreBuiltInAndNotDeprecated(), + self::namesOfRulesThatAreConfigured() + ); + + self::assertEmpty($namesOfRulesThatAreNotDeprecatedAndNotConfigured, \sprintf( + "Failed asserting that rule set \"%s\" configures all non-deprecated fixers. Rules with the names\n\n%s\n\nare not configured.", + static::className(), + ' - ' . \implode("\n - ", $namesOfRulesThatAreNotDeprecatedAndNotConfigured) + )); + } + final public function testRuleSetConfiguresAllRulesThatAreConfigurableAndNotDeprecatedWithAnExplicitConfigurationWithEveryOptionWhenTheyAreEnabled(): void { $rules = self::createRuleSet()->rules(); @@ -103,4 +117,17 @@ final public function testRuleSetConfiguresAllRulesThatAreConfigurableAndNotDepr static::className() )); } + + /** + * @phpstan-return list + * @psalm-return list + * + * @return array + */ + private static function namesOfRulesThatAreBuiltInAndNotDeprecated(): array + { + return \array_keys(\array_filter(self::fixersThatAreBuiltIn(), static function (Fixer\FixerInterface $fixer): bool { + return !$fixer instanceof Fixer\DeprecatedFixerInterface; + })); + } }