Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Require all configurable rules to be explicitly configured when enabled #644

Merged
merged 7 commits into from
Aug 19, 2022
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ For a full diff see [`4.6.0...main`][4.6.0...main].

- Updated `friendsofphp/php-cs-fixer` ([#642]), by [@dependabot]

### Fixed

- Require all configurable rules to be explicitly configured when enabled and part of an `ExplicitRuleSet` ([#644]), by [@localheinz]

## [`4.6.0`][4.6.0]

For a full diff see [`4.5.3...4.6.0`][4.5.3...4.6.0].
Expand Down Expand Up @@ -717,6 +721,7 @@ For a full diff see [`d899e77...1.0.0`][d899e77...1.0.0].
[#636]: https://github.com/ergebnis/php-cs-fixer-config/pull/636
[#637]: https://github.com/ergebnis/php-cs-fixer-config/pull/637
[#642]: https://github.com/ergebnis/php-cs-fixer-config/pull/642
[#644]: https://github.com/ergebnis/php-cs-fixer-config/pull/644

[@dependabot]: https://github.com/apps/dependabot
[@linuxjuggler]: https://github.com/linuxjuggler
Expand Down
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,4 @@
<code>registerBuiltInFixers</code>
</InternalMethod>
</file>
<file src="test/Unit/RuleSet/ExplicitRuleSetTestCase.php">
<MissingClosureReturnType occurrences="1">
<code>static function (FixerConfiguration\FixerOptionInterface $fixerOption) {</code>
</MissingClosureReturnType>
</file>
</files>
25 changes: 20 additions & 5 deletions src/RuleSet/Php74.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,20 @@ final class Php74 extends AbstractRuleSet implements ExplicitRuleSet
'strict' => false,
],
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => [
'sets' => [
'@IMAP',
'@internal',
],
],
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
'no_alternative_syntax' => [
'fix_non_monolithic_code' => false,
],
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -524,7 +529,13 @@ final class Php74 extends AbstractRuleSet implements ExplicitRuleSet
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order' => [
'order' => [
'param',
'throws',
'return',
],
],
'phpdoc_order_by_value' => [
'annotations' => [
'author',
Expand Down Expand Up @@ -631,7 +642,9 @@ final class Php74 extends AbstractRuleSet implements ExplicitRuleSet
'property',
],
],
'single_import_per_statement' => true,
'single_import_per_statement' => [
'group_to_single_imports' => true,
],
'single_line_after_imports' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => [
Expand Down Expand Up @@ -746,7 +759,9 @@ final class Php74 extends AbstractRuleSet implements ExplicitRuleSet
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => false,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
Expand Down
25 changes: 20 additions & 5 deletions src/RuleSet/Php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,20 @@ final class Php80 extends AbstractRuleSet implements ExplicitRuleSet
'strict' => false,
],
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => [
'sets' => [
'@IMAP',
'@internal',
],
],
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
'no_alternative_syntax' => [
'fix_non_monolithic_code' => false,
],
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -525,7 +530,13 @@ final class Php80 extends AbstractRuleSet implements ExplicitRuleSet
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order' => [
'order' => [
'param',
'throws',
'return',
],
],
'phpdoc_order_by_value' => [
'annotations' => [
'author',
Expand Down Expand Up @@ -632,7 +643,9 @@ final class Php80 extends AbstractRuleSet implements ExplicitRuleSet
'property',
],
],
'single_import_per_statement' => true,
'single_import_per_statement' => [
'group_to_single_imports' => true,
],
'single_line_after_imports' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => [
Expand Down Expand Up @@ -749,7 +762,9 @@ final class Php80 extends AbstractRuleSet implements ExplicitRuleSet
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => false,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
Expand Down
25 changes: 20 additions & 5 deletions src/RuleSet/Php81.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,20 @@ final class Php81 extends AbstractRuleSet implements ExplicitRuleSet
'strict' => false,
],
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => [
'sets' => [
'@IMAP',
'@internal',
],
],
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
'no_alternative_syntax' => [
'fix_non_monolithic_code' => false,
],
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -526,7 +531,13 @@ final class Php81 extends AbstractRuleSet implements ExplicitRuleSet
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order' => [
'order' => [
'param',
'throws',
'return',
],
],
'phpdoc_order_by_value' => [
'annotations' => [
'author',
Expand Down Expand Up @@ -633,7 +644,9 @@ final class Php81 extends AbstractRuleSet implements ExplicitRuleSet
'property',
],
],
'single_import_per_statement' => true,
'single_import_per_statement' => [
'group_to_single_imports' => true,
],
'single_line_after_imports' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => [
Expand Down Expand Up @@ -752,7 +765,9 @@ final class Php81 extends AbstractRuleSet implements ExplicitRuleSet
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => false,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
Expand Down
30 changes: 20 additions & 10 deletions test/Unit/RuleSet/ExplicitRuleSetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ final public function testRuleSetConfiguresAllRulesThatAreConfigurableAndNotDepr
$rulesWithAllNonDeprecatedConfigurationOptions = \array_combine(
$namesOfRules,
\array_map(static function (string $nameOfRule, $ruleConfiguration) use ($fixersThatAreBuiltIn) {
if (!\is_array($ruleConfiguration)) {
return $ruleConfiguration;
if (false === $ruleConfiguration) {
return false;
}

$fixer = $fixersThatAreBuiltIn[$nameOfRule];
Expand All @@ -106,15 +106,25 @@ final public function testRuleSetConfiguresAllRulesThatAreConfigurableAndNotDepr
return !$fixerOption instanceof FixerConfiguration\DeprecatedFixerOptionInterface;
});

$ruleConfigurationWithAllNonDeprecatedConfigurationOptionsAndDefaultValues = \array_combine(
\array_map(static function (FixerConfiguration\FixerOptionInterface $fixerOption): string {
return $fixerOption->getName();
}, $nonDeprecatedConfigurationOptions),
\array_map(static function (FixerConfiguration\FixerOptionInterface $fixerOption) {
if (!$fixerOption->hasDefault()) {
return null;
}

return $fixerOption->getDefault();
}, $nonDeprecatedConfigurationOptions),
);

if (!\is_array($ruleConfiguration)) {
return $ruleConfigurationWithAllNonDeprecatedConfigurationOptionsAndDefaultValues;
}

$diff = \array_diff_key(
\array_combine(
\array_map(static function (FixerConfiguration\FixerOptionInterface $fixerOption): string {
return $fixerOption->getName();
}, $nonDeprecatedConfigurationOptions),
\array_map(static function (FixerConfiguration\FixerOptionInterface $fixerOption) {
return $fixerOption->getDefault();
}, $nonDeprecatedConfigurationOptions),
),
$ruleConfigurationWithAllNonDeprecatedConfigurationOptionsAndDefaultValues,
$ruleConfiguration,
);

Expand Down
25 changes: 20 additions & 5 deletions test/Unit/RuleSet/Php74Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,20 @@ final class Php74Test extends ExplicitRuleSetTestCase
'strict' => false,
],
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => [
'sets' => [
'@IMAP',
'@internal',
],
],
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
'no_alternative_syntax' => [
'fix_non_monolithic_code' => false,
],
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -530,7 +535,13 @@ final class Php74Test extends ExplicitRuleSetTestCase
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order' => [
'order' => [
'param',
'throws',
'return',
],
],
'phpdoc_order_by_value' => [
'annotations' => [
'author',
Expand Down Expand Up @@ -637,7 +648,9 @@ final class Php74Test extends ExplicitRuleSetTestCase
'property',
],
],
'single_import_per_statement' => true,
'single_import_per_statement' => [
'group_to_single_imports' => true,
],
'single_line_after_imports' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => [
Expand Down Expand Up @@ -752,7 +765,9 @@ final class Php74Test extends ExplicitRuleSetTestCase
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => false,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
Expand Down
25 changes: 20 additions & 5 deletions test/Unit/RuleSet/Php80Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,20 @@ final class Php80Test extends ExplicitRuleSetTestCase
'strict' => false,
],
'native_function_type_declaration_casing' => true,
'new_with_braces' => true,
'new_with_braces' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => [
'sets' => [
'@IMAP',
'@internal',
],
],
'no_alias_language_construct_call' => true,
'no_alternative_syntax' => true,
'no_alternative_syntax' => [
'fix_non_monolithic_code' => false,
],
'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
Expand Down Expand Up @@ -531,7 +536,13 @@ final class Php80Test extends ExplicitRuleSetTestCase
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_order' => [
'order' => [
'param',
'throws',
'return',
],
],
'phpdoc_order_by_value' => [
'annotations' => [
'author',
Expand Down Expand Up @@ -638,7 +649,9 @@ final class Php80Test extends ExplicitRuleSetTestCase
'property',
],
],
'single_import_per_statement' => true,
'single_import_per_statement' => [
'group_to_single_imports' => true,
],
'single_line_after_imports' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => [
Expand Down Expand Up @@ -755,7 +768,9 @@ final class Php80Test extends ExplicitRuleSetTestCase
],
],
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => false,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
Expand Down
Loading