Skip to content

Commit

Permalink
Fix: Only require implementations of ExplicitRuleSet to configure eve…
Browse files Browse the repository at this point in the history
…ry non-deprecated rule
  • Loading branch information
localheinz committed Dec 26, 2020
1 parent 1806810 commit 2a06c2d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/RuleSet/ExplicitRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
26 changes: 1 addition & 25 deletions test/Unit/RuleSet/AbstractRuleSetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -320,7 +306,7 @@ final protected static function sort(array $data): array
/**
* @return array<int, string>
*/
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.
Expand Down Expand Up @@ -358,14 +344,4 @@ private static function namesOfRulesThatAreBuiltInAndDeprecated(): array
return $fixer instanceof Fixer\DeprecatedFixerInterface;
}));
}

/**
* @return array<int, string>
*/
private static function namesOfRulesThatAreBuiltInAndNotDeprecated(): array
{
return \array_keys(\array_filter(self::fixersThatAreBuiltIn(), static function (Fixer\FixerInterface $fixer): bool {
return !$fixer instanceof Fixer\DeprecatedFixerInterface;
}));
}
}
24 changes: 24 additions & 0 deletions test/Unit/RuleSet/ExplicitRuleSetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -103,4 +117,14 @@ final public function testRuleSetConfiguresAllRulesThatAreConfigurableAndNotDepr
static::className()
));
}

/**
* @return array<int, string>
*/
private static function namesOfRulesThatAreBuiltInAndNotDeprecated(): array
{
return \array_keys(\array_filter(self::fixersThatAreBuiltIn(), static function (Fixer\FixerInterface $fixer): bool {
return !$fixer instanceof Fixer\DeprecatedFixerInterface;
}));
}
}

0 comments on commit 2a06c2d

Please sign in to comment.