diff --git a/CHANGELOG.md b/CHANGELOG.md index edfa15d1..65775c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]. @@ -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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d54e5399..7f63f94c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -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> diff --git a/src/RuleSet/Php74.php b/src/RuleSet/Php74.php index 2ef918ac..3f75871c 100644 --- a/src/RuleSet/Php74.php +++ b/src/RuleSet/Php74.php @@ -276,7 +276,10 @@ 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', @@ -284,7 +287,9 @@ final class Php74 extends AbstractRuleSet implements ExplicitRuleSet ], ], '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, @@ -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', @@ -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' => [ @@ -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, diff --git a/src/RuleSet/Php80.php b/src/RuleSet/Php80.php index 352a44a6..e89107ae 100644 --- a/src/RuleSet/Php80.php +++ b/src/RuleSet/Php80.php @@ -276,7 +276,10 @@ 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', @@ -284,7 +287,9 @@ final class Php80 extends AbstractRuleSet implements ExplicitRuleSet ], ], '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, @@ -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', @@ -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' => [ @@ -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, diff --git a/src/RuleSet/Php81.php b/src/RuleSet/Php81.php index 52334ae1..649987c7 100644 --- a/src/RuleSet/Php81.php +++ b/src/RuleSet/Php81.php @@ -276,7 +276,10 @@ 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', @@ -284,7 +287,9 @@ final class Php81 extends AbstractRuleSet implements ExplicitRuleSet ], ], '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, @@ -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', @@ -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' => [ @@ -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, diff --git a/test/Unit/RuleSet/ExplicitRuleSetTestCase.php b/test/Unit/RuleSet/ExplicitRuleSetTestCase.php index 41124f5c..0f02051c 100644 --- a/test/Unit/RuleSet/ExplicitRuleSetTestCase.php +++ b/test/Unit/RuleSet/ExplicitRuleSetTestCase.php @@ -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]; @@ -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, ); diff --git a/test/Unit/RuleSet/Php74Test.php b/test/Unit/RuleSet/Php74Test.php index 9502b0e2..8df9eaf7 100644 --- a/test/Unit/RuleSet/Php74Test.php +++ b/test/Unit/RuleSet/Php74Test.php @@ -282,7 +282,10 @@ 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', @@ -290,7 +293,9 @@ final class Php74Test extends ExplicitRuleSetTestCase ], ], '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, @@ -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', @@ -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' => [ @@ -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, diff --git a/test/Unit/RuleSet/Php80Test.php b/test/Unit/RuleSet/Php80Test.php index cc8d5b12..238ee482 100644 --- a/test/Unit/RuleSet/Php80Test.php +++ b/test/Unit/RuleSet/Php80Test.php @@ -282,7 +282,10 @@ 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', @@ -290,7 +293,9 @@ final class Php80Test extends ExplicitRuleSetTestCase ], ], '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, @@ -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', @@ -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' => [ @@ -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, diff --git a/test/Unit/RuleSet/Php81Test.php b/test/Unit/RuleSet/Php81Test.php index 77866b74..8c58947e 100644 --- a/test/Unit/RuleSet/Php81Test.php +++ b/test/Unit/RuleSet/Php81Test.php @@ -282,7 +282,10 @@ final class Php81Test 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', @@ -290,7 +293,9 @@ final class Php81Test extends ExplicitRuleSetTestCase ], ], '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, @@ -532,7 +537,13 @@ final class Php81Test 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', @@ -639,7 +650,9 @@ final class Php81Test 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' => [ @@ -758,7 +771,9 @@ final class Php81Test 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,