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

List all the fixable rules in CLI via --list-rules #3737

Merged
merged 7 commits into from
Sep 20, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 826
PYTEST_REQPASS: 827
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
4 changes: 3 additions & 1 deletion src/ansiblelint/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ansiblelint.config import PROFILES
from ansiblelint.constants import RULE_DOC_URL
from ansiblelint.rules import RulesCollection
from ansiblelint.rules import RulesCollection, TransformMixin

DOC_HEADER = """
# Default Rules
Expand All @@ -27,6 +27,8 @@ def rules_as_str(rules: RulesCollection) -> RenderableType:
"""Return rules as string."""
table = Table(show_header=False, header_style="title", box=box.SIMPLE)
for rule in rules.alphabetical():
if issubclass(rule.__class__, TransformMixin):
rule.tags.insert(0, "autofix")
tag = f"[dim] ({', '.join(rule.tags)})[/dim]" if rule.tags else ""
table.add_row(
f"[link={RULE_DOC_URL}{rule.id}/]{rule.id}[/link]",
Expand Down
7 changes: 7 additions & 0 deletions test/test_list_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def test_list_rules_includes_opt_in_rules(project_path: Path) -> None:
assert ("opt-in" in result_list_rules.stdout) is True


def test_list_rules_includes_autofix() -> None:
"""Checks that listing rules also includes the autofix label for applicable rules."""
result_list_rules = run_ansible_lint("--list-rules")

assert ("autofix" in result_list_rules.stdout) is True


@pytest.mark.parametrize(
("result", "returncode", "format_string"),
(
Expand Down