Skip to content

Commit a1e957e

Browse files
committed
Reformatted with Black
Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 119bcc5 commit a1e957e

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

scripts/markdown-code-checker.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import argparse
44
import sys
55

6+
67
def extract_inline_code(file_path, languages):
78
"""extract inline code, language from markdown"""
8-
9+
910
with open(file_path, "r") as f:
1011
content = f.read()
1112

@@ -16,22 +17,24 @@ def extract_inline_code(file_path, languages):
1617
for child in ast.children:
1718
# TODO: add a way to exclude a code snippet
1819
if isinstance(child, md.block.FencedCode) and child.lang in languages:
19-
code_snippet_count+=1
20+
code_snippet_count += 1
2021
yield (code_snippet_count, child.lang, child.children[0].children)
2122

23+
2224
ignored_dirs = [".git"]
2325

26+
2427
def get_markdown_files(start, languages):
2528
"""locate all markdown files and call check_code_syntax on them"""
2629

2730
if os.path.isfile(start):
2831
check_code_syntax(start, languages)
2932

3033
for root, dirs, files in os.walk(start):
31-
dirs[:] = [d for d in dirs if d not in ignored_dirs]
34+
dirs[:] = [d for d in dirs if d not in ignored_dirs]
3235

3336
for f in files:
34-
if f.endswith('.markdown') or f.endswith('.md'):
37+
if f.endswith(".markdown") or f.endswith(".md"):
3538
path = os.path.join(root, f)
3639
check_code_syntax(path, languages)
3740

@@ -60,17 +63,31 @@ def check_code_syntax(path, languages):
6063

6164

6265
def write_file(file_name, extension, code_snippet):
63-
with open(f"{file_name}.{extension}", 'w') as f:
66+
with open(f"{file_name}.{extension}", "w") as f:
6467
f.write(code_snippet)
6568

6669

6770
def parse_args():
68-
parser = argparse.ArgumentParser(prog="Markdown inline code syntax checker",
69-
description="checks the syntax of documentation inline code"
70-
)
71-
parser.add_argument("--path", "-p", help="path of file or directory to check syntax on", default=".", required=False)
72-
parser.add_argument("--languages", "-l", nargs='+', help="languages to check syntax of", default=["cf3", "json", "yaml"], required=False)
73-
71+
parser = argparse.ArgumentParser(
72+
prog="Markdown inline code syntax checker",
73+
description="checks the syntax of documentation inline code",
74+
)
75+
parser.add_argument(
76+
"--path",
77+
"-p",
78+
help="path of file or directory to check syntax on",
79+
default=".",
80+
required=False,
81+
)
82+
parser.add_argument(
83+
"--languages",
84+
"-l",
85+
nargs="+",
86+
help="languages to check syntax of",
87+
default=["cf3", "json", "yaml"],
88+
required=False,
89+
)
90+
7491
return parser.parse_args()
7592

7693

@@ -84,7 +101,9 @@ def parse_args():
84101

85102
for language in args.languages:
86103
if language not in supported_languages:
87-
print(f"[error] Unsupported language '{language}'. The supported languages are: {", ".join(supported_languages)}")
104+
print(
105+
f"[error] Unsupported language '{language}'. The supported languages are: {", ".join(supported_languages)}"
106+
)
88107
sys.exit(-1)
89108

90109
get_markdown_files(args.path, args.languages)

0 commit comments

Comments
 (0)