-
Notifications
You must be signed in to change notification settings - Fork 280
transpile: Run rustfmt on generated .rs files
#1458
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
base: master
Are you sure you want to change the base?
Conversation
cc8a44b to
f519f02
Compare
| if !status.map_or(false, |status| status.success()) { | ||
| warn!("rustfmt failed, code may not be well-formatted"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle these errors differently? The command will fail if rustc isn't found or something, and the status will fail if rustc exits with an error. That said, they shouldn't really fail, so I think we can just panic here, maybe with an .expect.
Also, if we're calling rustfmt here, we can remove the rustfmt run in snapshots.rs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a panic is appropriate, as this is just an extra convenience for the user and not a hard requirement of the transpilation process. The transpilation should still succeed if rustfmt is not installed or doesn't complete for whatever reason. Though unlikely, rustfmt may not be installed even if cargo and rustc are.
3c732f2 to
9e83e14
Compare
| let output_path = build_dir.join(file_name); | ||
| let output = reg.render("lib.rs", &json).unwrap(); | ||
| let path = maybe_write_to_file(&output_path, output, tcfg.overwrite_existing)?; | ||
| rustfmt(&output_path, build_dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this optional (with a command line argument)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we not do it, though?
rustfmtwhen translating #742.Rather than running
cargo fmt, this runs therustfmtbinary directly so that it can be used on individual files, and also when there are no build files.