Skip to content
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 --check flag to cargo fmt #3890

Merged
merged 1 commit into from
Oct 27, 2019

Conversation

calebcartwright
Copy link
Member

Resolves #3888

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@@ -104,6 +108,12 @@ fn execute() -> i32 {

let strategy = CargoFmtStrategy::from_opts(&opts);
let mut rustfmt_args = opts.rustfmt_options;
if opts.check {
let check_flag = String::from("--check");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we can defer the allocation of a String until we absolutely need it:

let check_flag = "--check";
if !rustfmt_args.contains(check_flag) {
    rustfmt_args.push(check_flag.to_owned());
}

Copy link
Member Author

@calebcartwright calebcartwright Oct 26, 2019

Choose a reason for hiding this comment

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

Unfortunately I believe the limitations with Vec::contains that we ran into in #3752 (comment) still exist which prevent using a literal as an arg.

On a related note, I was going to volunteer to work on #3587 and while working on that I'll also look into consolidating the way cargo fmt is transforming/passing flags (like --message-format --> --emit, --check, etc.) to rustfmt which I think may help remove some of these Vec::contains

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh my god, I am so dumb 😩 Sorry about that!

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries!

@topecongiro topecongiro added this to the 2.0.0 milestone Oct 27, 2019
@topecongiro topecongiro merged commit 801cb98 into rust-lang:master Oct 27, 2019
@calebcartwright calebcartwright deleted the cargo-fmt-check branch October 28, 2019 01:55
calebcartwright added a commit to calebcartwright/rustfmt that referenced this pull request Sep 17, 2021
@karyon
Copy link
Contributor

karyon commented Oct 27, 2021

backported in #4993

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

Successfully merging this pull request may close these issues.

Add --check command-line flag to cargo-fmt
3 participants