Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/cfengine_cli/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def _process_markdown_code_blocks(
return

if syntax_check:
# We currently only print the filenames during linting, not formatting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olehermanse was there a specific reason for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic is / was slightly different. During linting we always print the filenames with a pass or fail message.

On formatting we (should) print only the ones that were reformatted. I think in the beginning there was no code / return code to track whether something was reformatted or not.

It might also have been harder to get this information. When we use tools like prettier and black for formatting, they might have different patterns for their outputs. And I know we have switched in the past between running those tools on single files (slow, but more controlled) vs on entire directories (faster, but more complicated output / results).

We now do this in cfengine format, only printing on reformatting, so it makes sense to do in in cfengine dev format-docs as well.

print(
f"Processing code blocks (snippets) inside {origin_paths_len} markdown files:"
)
Expand All @@ -265,9 +264,13 @@ def _process_markdown_code_blocks(
spaces = " " * (4 - len(str(percentage)))
prefix = f"[{origin_paths_i + 1}/{origin_paths_len}{spaces}({percentage}%)] "
offset = 0
original_content = None
if syntax_check and not parsed_markdowns["files"][origin_path]["code-blocks"]:
print(f"{prefix}SKIP: No code blocks in '{origin_path}'")
continue
if autoformat:
with open(origin_path, "r") as f:
original_content = f.read()
for i, code_block in enumerate(
parsed_markdowns["files"][origin_path]["code-blocks"]
):
Expand Down Expand Up @@ -345,6 +348,12 @@ def _process_markdown_code_blocks(
if cleanup:
os.remove(snippet_path)

if autoformat:
with open(origin_path, "r") as f:
new_content = f.read()
if new_content != original_content:
print(f"Markdown file '{origin_path}' was reformatted")


def _run_formatter(tool, args, cwd, install_hint):
print(f"Formatting with {tool}...")
Expand Down
Loading