-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
executable file
·82 lines (64 loc) · 1.57 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import glob
import itertools
import os.path
import sys
from lintlify import openapi
from lintlify.context import LintContext
from lintlify.error import LintError
from lintlify.linters.code_blocks import lint_all_code_blocks
from lintlify.linters.frontmatter import lint_all_frontmatter
def get_repo_dir() -> str:
return os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"..",
)
)
def get_docs_dir() -> str:
return os.path.join(
get_repo_dir(),
"docs",
)
def get_all_mdx_filenames(
*,
docs_dir: str,
) -> list[str]:
return glob.glob(
os.path.join(
docs_dir,
"**",
"*.mdx",
),
recursive=True,
)
def print_error(error: LintError) -> None:
print("==============")
print(f"ERROR: {error.filename}")
print(error.message)
def main() -> None:
docs_dir: str = get_docs_dir()
lint_context: LintContext = LintContext(
repository_root=get_repo_dir(),
openapi_files=openapi.get_all_openapi_files(
docs_dir=docs_dir,
),
mdx_files=get_all_mdx_filenames(
docs_dir=docs_dir,
),
)
has_error: bool = False
for error in itertools.chain(
lint_all_frontmatter(
lint_context=lint_context,
),
lint_all_code_blocks(
lint_context=lint_context,
),
):
has_error = True
print_error(error)
if has_error:
sys.exit(1)
if __name__ == "__main__":
main()