File: gen_checks.py

package info (click to toggle)
python-refurb 1.27.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,700 kB
  • sloc: python: 9,468; makefile: 40; sh: 6
file content (39 lines) | stat: -rw-r--r-- 972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import re
from pathlib import Path
from textwrap import dedent

from refurb.error import ErrorCode
from refurb.loader import get_error_class, get_modules

docs: dict[str, str] = {}

for module in get_modules([]):
    if error := get_error_class(module):
        error_code = ErrorCode.from_error(error)

        header = f"## {error_code}: `{error.name}`"

        categories = " ".join(f"`{cat}`" for cat in error.categories)
        categories = "Categories: " + categories

        body = dedent(error.__doc__ or "").strip()
        body = re.sub(r"```([\s\S]*?)```", r"```python\1```", body)

        docs[str(error_code)] = "\n\n".join([header, categories, body])


HEADER = """\
<!--
Autogenerated! Do not modify!

See the "Updating Documentation" section of the README file for more info.
-->

# Available Checks"""


with (Path(__file__).parent / "checks.md").open("w+") as f:
    f.write(HEADER)

    for _, v in sorted(docs.items()):
        f.write(f"\n\n{v}")