From 046ff90e9aa7eb87450ed38ee4ab8a1cba3ee1e2 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Thu, 17 Nov 2022 17:50:45 +0100 Subject: [PATCH] docs: Fix docs for disabled rules in rulesets (#6679) --- doc/ruleSets/PhpCsFixer.rst | 6 +- doc/ruleSets/SymfonyRisky.rst | 6 +- .../RuleSetDocumentationGenerator.php | 57 +++++++++++-------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index 35b4e0a54c0..bf399fcbb62 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -52,7 +52,11 @@ Rules - `phpdoc_var_annotation_correct_order <./../rules/phpdoc/phpdoc_var_annotation_correct_order.rst>`_ - `return_assignment <./../rules/return_notation/return_assignment.rst>`_ - `single_line_comment_style <./../rules/comment/single_line_comment_style.rst>`_ -- `single_line_throw <./../rules/function_notation/single_line_throw.rst>`_ - `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_ config: ``['ensure_single_space' => true]`` + +Disabled rules +-------------- + +- `single_line_throw <./../rules/function_notation/single_line_throw.rst>`_ diff --git a/doc/ruleSets/SymfonyRisky.rst b/doc/ruleSets/SymfonyRisky.rst index 5a63122ce17..8dd4e3eef38 100644 --- a/doc/ruleSets/SymfonyRisky.rst +++ b/doc/ruleSets/SymfonyRisky.rst @@ -31,7 +31,6 @@ Rules - `no_homoglyph_names <./../rules/naming/no_homoglyph_names.rst>`_ - `no_php4_constructor <./../rules/class_notation/no_php4_constructor.rst>`_ - `no_unneeded_final_method <./../rules/class_notation/no_unneeded_final_method.rst>`_ -- `no_unreachable_default_argument_value <./../rules/function_notation/no_unreachable_default_argument_value.rst>`_ - `no_useless_sprintf <./../rules/function_notation/no_useless_sprintf.rst>`_ - `non_printable_character <./../rules/basic/non_printable_character.rst>`_ - `ordered_traits <./../rules/class_notation/ordered_traits.rst>`_ @@ -45,3 +44,8 @@ Rules - `string_length_to_empty <./../rules/string_notation/string_length_to_empty.rst>`_ - `string_line_ending <./../rules/string_notation/string_line_ending.rst>`_ - `ternary_to_elvis_operator <./../rules/operator/ternary_to_elvis_operator.rst>`_ + +Disabled rules +-------------- + +- `no_unreachable_default_argument_value <./../rules/function_notation/no_unreachable_default_argument_value.rst>`_ diff --git a/src/Documentation/RuleSetDocumentationGenerator.php b/src/Documentation/RuleSetDocumentationGenerator.php index 81b879400e3..bc9f8c10ef1 100644 --- a/src/Documentation/RuleSetDocumentationGenerator.php +++ b/src/Documentation/RuleSetDocumentationGenerator.php @@ -50,34 +50,45 @@ public function generateRuleSetsDocumentation(RuleSetDescriptionInterface $defin $doc .= ' This set contains rules that are risky.'; } - $doc .= "\n\n"; - $rules = $definition->getRules(); - if (\count($rules) < 1) { - $doc .= 'This is an empty set.'; + if ([] === $rules) { + $doc .= "\n\nThis is an empty set."; } else { - $doc .= "Rules\n-----\n"; - - foreach ($rules as $rule => $config) { - if (str_starts_with($rule, '@')) { - $ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($rule); - $ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/')); - - $doc .= "\n- `{$rule} <.{$ruleSetPath}>`_"; - } else { - $path = Preg::replace( - '#^'.preg_quote($this->locator->getFixersDocumentationDirectoryPath(), '#').'/#', - './../rules/', - $this->locator->getFixerDocumentationFilePath($fixerNames[$rule]) - ); - - $doc .= "\n- `{$rule} <{$path}>`_"; + $enabledRules = array_filter($rules, static fn ($config) => false !== $config); + $disabledRules = array_filter($rules, static fn ($config) => false === $config); + + $listRules = function (array $rules) use (&$doc, $fixerNames): void { + foreach ($rules as $rule => $config) { + if (str_starts_with($rule, '@')) { + $ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($rule); + $ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/')); + + $doc .= "\n- `{$rule} <.{$ruleSetPath}>`_"; + } else { + $path = Preg::replace( + '#^'.preg_quote($this->locator->getFixersDocumentationDirectoryPath(), '#').'/#', + './../rules/', + $this->locator->getFixerDocumentationFilePath($fixerNames[$rule]) + ); + + $doc .= "\n- `{$rule} <{$path}>`_"; + } + + if (!\is_bool($config)) { + $doc .= "\n config:\n ``".HelpCommand::toString($config).'``'; + } } + }; - if (!\is_bool($config)) { - $doc .= "\n config:\n ``".HelpCommand::toString($config).'``'; - } + if ([] !== $enabledRules) { + $doc .= "\n\nRules\n-----\n"; + $listRules($enabledRules); + } + + if ([] !== $disabledRules) { + $doc .= "\n\nDisabled rules\n--------------\n"; + $listRules($disabledRules); } }