Skip to content

Commit dcca424

Browse files
shatakshiiiipre-commit-ci[bot]ssbarnea
authored
Make the autofix rule list dynamic in documentation (#3785)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sorin Sbarnea <[email protected]>
1 parent 93b50d8 commit dcca424

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

docs/_autofix_rules.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- [command-instead-of-shell](rules/command-instead-of-shell.md)
2+
- [deprecated-local-action](rules/deprecated-local-action.md)
3+
- [fqcn](rules/fqcn.md)
4+
- [jinja](rules/jinja.md)
5+
- [key-order](rules/key-order.md)
6+
- [name](rules/name.md)
7+
- [no-free-form](rules/no-free-form.md)
8+
- [no-jinja-when](rules/no-jinja-when.md)
9+
- [no-log-password](rules/no-log-password.md)
10+
- [partial-become](rules/partial-become.md)

docs/autofix.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ You can disable running transforms by setting `write_list: ["none"]`. Or only en
88

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

11-
- [command-instead-of-shell](rules/command-instead-of-shell.md#auto-fixing-capability)
12-
- [deprecated-local-action](rules/deprecated-local-action.md)
13-
- [fqcn](rules/fqcn.md)
14-
- [jinja](rules/jinja.md)
15-
- [key-order](rules/key-order.md)
16-
- [name](rules/name.md)
17-
- [no-free-form](rules/no-free-form.md)
18-
- [no-jinja-when](rules/no-jinja-when.md)
19-
- [no-log-password](rules/no-log-password.md)
20-
- [partial-become](rules/partial-become.md)
11+
```yaml
12+
{!_autofix_rules.md!}
13+
```

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ nav:
110110
- Contributing: contributing.md
111111
- custom-rules.md
112112

113+
exclude_docs: |
114+
_autofix_rules.md
115+
113116
plugins:
114117
- autorefs
115118
- markdown-exec

tools/generate_docs.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
#!/bin/env python3
22
"""Script that tests rule markdown documentation."""
3+
from __future__ import annotations
4+
35
import subprocess
6+
from pathlib import Path
7+
8+
from ansiblelint.cli import get_rules_dirs
9+
from ansiblelint.config import Options
10+
from ansiblelint.rules import RulesCollection, TransformMixin
11+
12+
if __name__ == "__main__":
13+
subprocess.run(
14+
"ansible-lint -L --format=md", # noqa: S607
15+
shell=True, # noqa: S602
16+
check=True,
17+
stdout=subprocess.DEVNULL,
18+
)
19+
20+
file = Path("docs/_autofix_rules.md")
21+
options = Options()
22+
options.rulesdirs = get_rules_dirs([])
23+
options.list_rules = True
24+
rules = RulesCollection(
25+
options.rulesdirs,
26+
options=options,
27+
)
28+
contents: list[str] = []
29+
for rule in rules.alphabetical():
30+
if issubclass(rule.__class__, TransformMixin):
31+
url = f"rules/{rule.id}.md"
32+
contents.append(f"- [{rule.id}]({url})\n")
433

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

0 commit comments

Comments
 (0)