mdformat
mdformat copied to clipboard
Provide an option to apply changes and exit non-zero if changes were made
Context
Similar to this ticket and this one filed for the ruff formatter, it would be valuable to apply changes and return 1 . Currently we can only choose one or the other.
All of the arguments in favor of this behavior are in the linked tickets, but here's a summary from my POV:
- It's useful in CI to be able to print a diff of what changed, and it's easy to do that by actually applying the change
- Some repo task runners get tripped up when a tool modifies its inputs without returning a non-zero result: https://github.com/moonrepo/moon/issues/1959
-
mdformatdoes not print out any info about files that it changed, so I can't do this by parsing output
Proposal
Since ruff is such a popular linter, I propose that we add a flag with the same name: --exit-non-zero-on-format. This flag will tell mdformat to return non-zero if any files were modified.
This would be a super quick fix, so I'm happy to make the change myself if there are no objections.