From b4b8b2c9072a8a24b2a00c50ff71fcc082a6f73f Mon Sep 17 00:00:00 2001 From: Shatakshi Mishra Date: Wed, 20 Sep 2023 19:43:33 +0530 Subject: [PATCH] List all the fixable rules in CLI via `--list-rules` (#3737) --- .github/workflows/tox.yml | 2 +- src/ansiblelint/generate_docs.py | 4 +++- test/test_list_rules.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 2ee2c8c195..ef1b769eb7 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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')" diff --git a/src/ansiblelint/generate_docs.py b/src/ansiblelint/generate_docs.py index 1498a67790..3a95de33aa 100644 --- a/src/ansiblelint/generate_docs.py +++ b/src/ansiblelint/generate_docs.py @@ -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 @@ -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]", diff --git a/test/test_list_rules.py b/test/test_list_rules.py index dab16e3012..85ef53fb05 100644 --- a/test/test_list_rules.py +++ b/test/test_list_rules.py @@ -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"), (