-
Notifications
You must be signed in to change notification settings - Fork 926
--check
silently ignored when formatting from stdin
#3871
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
Comments
When using stdin input, rustfmt will always use stdout emit mode (by design). However, as you noted, because of this rustfmt is silently ignoring the I don't think it'll be viable to support the various file emit modes with stdin (include the diff emit mode that comes with I suppose we could have rustfmt err if you include |
Well, we can support |
I agree, if it's possible to emit diffs (with If not, an error (as occurs with |
I'd be interested in working on this - making it an error as a first step, and then looking into making |
Currently, the checkstyle and json emitters would not handle Lines 40 to 60 in 69c7dbc
https://github.com/rust-lang/rustfmt/blob/master/src/emitter/checkstyle.rs#L23-L37 I included the file path check when I implemented the json emitter because it was there in the checkstyle emitter, though in hindsight I'm not sure if that's really required I don't see any reason why [
{
"name":"tests/writemode/source/json.rs",
"mismatches":[
{
"original_begin_line":5,
"original_end_line":7,
"expected_begin_line":5,
"expected_end_line":5,
"original":"fn foo_expr() {\n 1\n}",
"expected":"fn foo_expr() { 1 }"
}
] The diff emitter (which is used with |
I've taken the liberty of speculatively doing the first step (returning errors) in #3875; I'll probably speculatively go ahead and try to make them work too. :-) |
I got some time to look at making the other emit modes work on this branch. I haven't done any tests so far for the changes though. Looking through, |
I'd take a look at Lines 409 to 429 in 69c7dbc
and the in-file unit tests for the relevant emitters |
Thanks @calebcartwright , that was very useful. I've raised a new PR with the JSON and checkstyle emitters now working with stdin (not yet |
Thanks @jugglerchris! Will respond to your question over in #3894 |
Have I missed any parts to this or do we think this can be closed? |
Was the diff emitter updated? That's the emitter used with |
You can't select it explicitly with
|
I know, but if the only formatting issue is line endings and/or the user also includes the Obviously that'd be a pretty weird user behavior, but I do think it'd be worth making the same updates to avoid such a scenario/error. Whether that's updating the emitter or just checking for the presence of the |
Ok, I do get a panic with |
I think the missing "Incorrect newline style" is because the |
👍 I believe your updates to the diff emitter will cover both cases. It's true that internally the parser normalizes line endings to unix style, so the |
Closed via #3910. |
When I run,
the output is equivalent to
rustfmt --emit stdout
. Ideally, I would like to see the above call emit something like,If that's not possible, a warning or error message noting the ignored option would make this behavior less surprising, and may help nudge users towards valid usage.
It might also be worth noting that
rustfmt +nightly --emit json
is silently ignored in the same situations.The text was updated successfully, but these errors were encountered: