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

docs: Fix docs for disabled rules in rulesets #6679

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/ruleSets/PhpCsFixer.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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