Skip to content

Return an error if --check or --emit json are used with stdin. #3875

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 4 commits into from
Oct 25, 2019

Conversation

jugglerchris
Copy link
Contributor

The intention is to implement these cases, but return an error is better than silently ignoring them in the meantime.
See #3871 .

src/bin/main.rs Outdated
@@ -464,6 +472,14 @@ fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
if minimal_config_path.is_some() {
return Err(OperationError::MinimalPathWithStdin);
}
if matches.opt_present("check") {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to move these checks into format_string (https://github.com/rust-lang/rustfmt/blob/master/src/bin/main.rs#L241) so that we can use the already parsed values? (options.check and emit_mode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds reasonable, yes - it didn't feel quite right comparing with a literal there! I'll take a look there, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved the check into format_string. I'm still returning Err(OperationError) but with added .into() to convert to FailureError - maybe ? would be better?

@jugglerchris
Copy link
Contributor Author

The CI failures seem to be unrelated to the changes here - I think it's the same as rust-lang/rust#65424

src/bin/main.rs Outdated
return Err(OperationError::CheckWithStdin);
}
if let Some(mode) = matches.opt_str("emit") {
if mode == "json" {
Copy link
Member

Choose a reason for hiding this comment

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

All of the emit modes other than stdout will currently fail with stdin (not just json), so I think this should check for any emit mode other than stdout and fail accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll tweak it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit broken, since the default is --emit=files. format_string just overrides whatever it was with stdout, but I think it needs to distinguish between an explicit --emit=files (which would be an error) and not being specified (in which case default to stdout), which suggests that options.emit_mode should be an Option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Fixed again)

@calebcartwright
Copy link
Member

calebcartwright commented Oct 19, 2019

The CI failures seem to be unrelated to the changes here - I think it's the same as rust-lang/rust#65424

Correct

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. Thanks!

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.

4 participants