Skip to content

CFE-4665: cfengine dev format docs should tell you what files it formatted#144

Open
sarakthon wants to merge 1 commit into
cfengine:mainfrom
sarakthon:print-formatted-files
Open

CFE-4665: cfengine dev format docs should tell you what files it formatted#144
sarakthon wants to merge 1 commit into
cfengine:mainfrom
sarakthon:print-formatted-files

Conversation

@sarakthon
Copy link
Copy Markdown
Contributor

Ticket: CFE-4665

@cf-bottom
Copy link
Copy Markdown

Thank you for submitting a PR! Maybe @larsewi can review this?

Copy link
Copy Markdown
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

🚀

Comment thread src/cfengine_cli/docs.py
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.

Comment thread src/cfengine_cli/docs.py
Comment on lines 229 to 231
def _process_markdown_code_blocks(
path, languages, extract, syntax_check, output_check, autoformat, replace, cleanup
):
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.

Unrelated, but I wish there was some doc string explaining these arguments. What is autoformat?

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.

Automatically format the code block.

Comment thread src/cfengine_cli/docs.py
Comment on lines +270 to +271
if autoformat:
print(f"Formatting '{origin_path}'")
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.

We should print messages like in cfengine format:

Policy file './content/resources/additional-topics/STIGs.cf' was reformatted

And these should only be printed if the file was reformatted (i.e. the file changed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants