-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add a --diff
flag to show changes without modifying the source file
#268
Comments
--diff
flag to show changes without modifying the source file
Thanks for the issue! I'm not too excited about this feature as
I'll leave this open for now so we can reconsider if there's demand and real-life use cases from other users. |
Well, I'm not too excited about the |
In passing, I note that |
I think a real use case could be that people submit a PR for documents in Markdown files via the Github web editor. If they make an error, CI will fail, but there is no way to tell the user what the formatting problem is. In many cases these people cannot use a development environment, but it is possible to fix their PRs with the diff output. |
That assumes you are using 1) a shell 2) one that has the process substitution feature. Neither is the case if you are running it via Lots of formatters have this feature exactly for this reason: so that there's an easy way to show the diff in CI logs. |
Description / Summary
A nice-to-have feature would be for mdformat to show the changes it would make to the file by writing the output to stdout rather than to the original file. This is a feature that black has, using the
--diff
flag on the command line.Value / benefit
At present, the only way to find out the changes that
mdformat
will make (or has made) is to create a copy of the file to be formatted, runmdformat
on the copy and compare the two files. Or, if the file is under version control, to compare to the previous version (e.g. bygit diff
). The extra effort is a bit of a pest, but this feature is really just a nice-to-have.Implementation details
Black's implementation is in src/black/output.py#L55-L73:
There's a short
color_diff()
function directly after, if anyone wants to be fancy.Tasks to complete
No response
The text was updated successfully, but these errors were encountered: