Skip to content

Commit

Permalink
Make the autofix rule list dynamic in documentation (#3785)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 93b50d8 commit dcca424
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
10 changes: 10 additions & 0 deletions docs/_autofix_rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- [command-instead-of-shell](rules/command-instead-of-shell.md)
- [deprecated-local-action](rules/deprecated-local-action.md)
- [fqcn](rules/fqcn.md)
- [jinja](rules/jinja.md)
- [key-order](rules/key-order.md)
- [name](rules/name.md)
- [no-free-form](rules/no-free-form.md)
- [no-jinja-when](rules/no-jinja-when.md)
- [no-log-password](rules/no-log-password.md)
- [partial-become](rules/partial-become.md)
13 changes: 3 additions & 10 deletions docs/autofix.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ You can disable running transforms by setting `write_list: ["none"]`. Or only en

Following is the list of supported rules covered under autofix functionality.

- [command-instead-of-shell](rules/command-instead-of-shell.md#auto-fixing-capability)
- [deprecated-local-action](rules/deprecated-local-action.md)
- [fqcn](rules/fqcn.md)
- [jinja](rules/jinja.md)
- [key-order](rules/key-order.md)
- [name](rules/name.md)
- [no-free-form](rules/no-free-form.md)
- [no-jinja-when](rules/no-jinja-when.md)
- [no-log-password](rules/no-log-password.md)
- [partial-become](rules/partial-become.md)
```yaml
{!_autofix_rules.md!}
```
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ nav:
- Contributing: contributing.md
- custom-rules.md

exclude_docs: |
_autofix_rules.md
plugins:
- autorefs
- markdown-exec
Expand Down
38 changes: 32 additions & 6 deletions tools/generate_docs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#!/bin/env python3
"""Script that tests rule markdown documentation."""
from __future__ import annotations

import subprocess
from pathlib import Path

from ansiblelint.cli import get_rules_dirs
from ansiblelint.config import Options
from ansiblelint.rules import RulesCollection, TransformMixin

if __name__ == "__main__":
subprocess.run(
"ansible-lint -L --format=md", # noqa: S607
shell=True, # noqa: S602
check=True,
stdout=subprocess.DEVNULL,
)

file = Path("docs/_autofix_rules.md")
options = Options()
options.rulesdirs = get_rules_dirs([])
options.list_rules = True
rules = RulesCollection(
options.rulesdirs,
options=options,
)
contents: list[str] = []
for rule in rules.alphabetical():
if issubclass(rule.__class__, TransformMixin):
url = f"rules/{rule.id}.md"
contents.append(f"- [{rule.id}]({url})\n")

subprocess.run(
"ansible-lint -L --format=md", # noqa: S607
shell=True, # noqa: S602
check=True,
stdout=subprocess.DEVNULL,
)
# Write the injected contents to the file.
with file.open(encoding="utf-8", mode="w") as fh:
fh.writelines(contents)

0 comments on commit dcca424

Please sign in to comment.