Skip to content

Option for --check to list violating files only #3738

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

Closed
abonander opened this issue Aug 12, 2019 · 4 comments · Fixed by #3747
Closed

Option for --check to list violating files only #3738

abonander opened this issue Aug 12, 2019 · 4 comments · Fixed by #3747

Comments

@abonander
Copy link

abonander commented Aug 12, 2019

For our CI script we just want to say "cargo fmt needs to be run, here's the files that need it" which doesn't appear to be possible using --check. The diff output is kind of too noisy to be useful unless you expect the committer to actually fix the files by hand.

@calebcartwright
Copy link
Member

calebcartwright commented Aug 12, 2019

I was just thinking about this one the other day, kinda like how black for python displays a x file(s) would be reformatted message when the --check flag is included, or x file(s) reformatted when the formatting is actually applied.

There's a request (#3274) to add support for the --message-format flag found in other cargo subcommands, and one of the options for that flag is short

Do you think something like the below would work for to generate the list of files?
cargo fmt --message-format short -- --check

@topecongiro
Copy link
Contributor

We can add a command line flag like the -l,--files-with-matches of rg:

# Run `cargo fmt -- --check` but only prints file names which will be formatted
cargo fmt -- --check -l
# Run `cargo fmt` and print file names that were formatted
cargo fmt -- -l

@calebcartwright
Copy link
Member

Even better! I'd be happy to look at implementing this @topecongiro once I've finished up my work with the json and checkstyle emitters

@abonander
Copy link
Author

That was quick! Awesome!

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

Successfully merging a pull request may close this issue.

3 participants