Skip to content

Commit

Permalink
docs: Fix docs for disabled rules in rulesets (#6679)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Nov 17, 2022
1 parent b577444 commit 046ff90
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
6 changes: 5 additions & 1 deletion doc/ruleSets/PhpCsFixer.rst
Expand Up @@ -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>`_
6 changes: 5 additions & 1 deletion doc/ruleSets/SymfonyRisky.rst
Expand Up @@ -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>`_
Expand All @@ -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>`_
57 changes: 34 additions & 23 deletions src/Documentation/RuleSetDocumentationGenerator.php
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 046ff90

Please sign in to comment.