-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <ssbarnea@redhat.com>
- Loading branch information
1 parent
93b50d8
commit dcca424
Showing
4 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |