Skip to content

Commit 36da93b

Browse files
committed
Small refactoring
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent 792b06e commit 36da93b

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/cfengine_cli/docs.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,15 @@ def fn_autoformat(_origin_path, snippet_path, language, _first_line, _last_line)
199199
raise UserError(f"Invalid json in '{snippet_path}'")
200200

201201

202-
def _markdown_code_checker(
203-
path, syntax_check, extract, replace, autoformat, languages, output_check, cleanup
202+
def _process_markdown_code_blocks(
203+
path, languages, extract, syntax_check, output_check, autoformat, replace, cleanup
204204
):
205205
supported_languages = {"cf3": "cf", "json": "json", "yaml": "yml"}
206206

207207
if not os.path.exists(path):
208208
raise UserError("This path doesn't exist")
209209

210+
# TODO: Switch to tree-sitter parser here:
210211
if (
211212
syntax_check
212213
and "cf3" in languages
@@ -263,6 +264,9 @@ def _markdown_code_checker(
263264
os.remove(snippet_path)
264265
raise e
265266

267+
if output_check and "noexecute" not in code_block["flags"]:
268+
fn_check_output()
269+
266270
if autoformat and "noautoformat" not in code_block["flags"]:
267271
fn_autoformat(
268272
origin_path,
@@ -272,9 +276,6 @@ def _markdown_code_checker(
272276
code_block["last_line"],
273277
)
274278

275-
if output_check and "noexecute" not in code_block["flags"]:
276-
fn_check_output()
277-
278279
if replace and "noreplace" not in code_block["flags"]:
279280
offset = fn_replace(
280281
origin_path,
@@ -332,14 +333,14 @@ def update_docs() -> int:
332333
print("Formatting markdown files with prettier...")
333334
_run_prettier()
334335
print("Formatting markdown code blocks according to our rules...")
335-
_markdown_code_checker(
336+
_process_markdown_code_blocks(
336337
path=".",
337-
syntax_check=False,
338+
languages=["json"], # TODO: Add cfengine3 here
338339
extract=True,
339-
replace=True,
340-
autoformat=True,
341-
languages=["json"],
340+
syntax_check=False,
342341
output_check=False,
342+
autoformat=True,
343+
replace=True,
343344
cleanup=True,
344345
)
345346
return 0
@@ -351,15 +352,15 @@ def check_docs() -> int:
351352
Currently only JSON syntax checking.
352353
353354
Run by the command:
354-
cfengine dev docs-checking"""
355-
_markdown_code_checker(
355+
cfengine dev docs-check"""
356+
_process_markdown_code_blocks(
356357
path=".",
357-
syntax_check=True,
358-
extract=True,
359-
replace=False,
360-
autoformat=False,
361358
languages=["json"],
359+
extract=True,
360+
syntax_check=True,
362361
output_check=False,
362+
autoformat=False,
363+
replace=False,
363364
cleanup=True,
364365
)
365366
return 0

0 commit comments

Comments
 (0)