Skip to content

Commit

Permalink
List all the fixable rules in CLI via --list-rules (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii authored Sep 20, 2023
1 parent c2e86d9 commit b4b8b2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit b4b8b2c

Please sign in to comment.