Skip to content

Commit

Permalink
Merge pull request #644 from ergebnis/fix/explicit
Browse files Browse the repository at this point in the history
Fix: Require all configurable rules to be explicitly configured when enabled
  • Loading branch information
localheinz committed Aug 19, 2022
2 parents 774bdb0 + c0a2688 commit a50f4af
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 45 deletions.
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

0 comments on commit a50f4af

Please sign in to comment.