Skip to content

fix(fmt): use non-zero exit code when formatting fails #28523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2025

Conversation

WWRS
Copy link
Contributor

@WWRS WWRS commented Mar 17, 2025

Fixes #28483

  • Added a counter in RealFormatter for files that failed to format (usually due to syntax error). If this isn't 0, finish now returns an error.
  • Moved related itests to specs

@CLAassistant
Copy link

CLAassistant commented Mar 17, 2025

CLA assistant check
All committers have signed the CLA.

@@ -1,4 +1,4 @@
Error formatting: [WILDCARD]broken.html
Syntax error (expected close tag) at file://[WILDCARD]broken.html:3:0

Checked 1 file
error: Failed to format 1 file in 1 file
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I feel like the duplicate file part is confusing to read. Maybe it should look something like this?

error: Failed to format 1 file

Copy link
Contributor Author

@WWRS WWRS Mar 17, 2025

Choose a reason for hiding this comment

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

This mirrors fmt --check, which reports a result like error: Found 5 not formatted files in 10 files

This PR would cause fmt to produce error: Failed to format 5 files in 10 files

I think all of these are reasonable:

  • The suggested error: Failed to format 5 files
  • The existing error: Failed to format 5 files in 10 files
  • Some clearer message, e.g. error: Failed to format 5 files of 10 checked files

Do you have a preference? And (if option 1 or option 3) should the message in fmt --check be changed to match?

Copy link
Contributor

Choose a reason for hiding this comment

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

@WWRS Can you change it to error: Failed to format 5 of 10 checked files? Would be fine either way with changing deno fmt --check to match.

Or let us know if you want us to finish the PR. We want to land this soon

Copy link
Contributor

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Nice work, also +1 on adding tests. Let's get rid of the duplicate file part in the output and then I think it's ready to be merged.

Copy link
Contributor

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nayeemrmn nayeemrmn merged commit dca9f7c into denoland:main Apr 4, 2025
18 checks passed
@WWRS WWRS deleted the fmt-exit-1 branch April 4, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zero 0 exit code when formatting with syntax error
4 participants