Skip to content

Commit

Permalink
fix: ignore rustfmt output on error status (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
bram209 committed Oct 10, 2023
1 parent 4198a62 commit adb98d2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn main() {
mut formatted,
}) => {
if args.rustfmt {
formatted = run_rustfmt(&formatted);
formatted = run_rustfmt(&formatted).unwrap_or(formatted);
}

if args.check && check_if_diff(None, &original, &formatted, true) {
Expand Down Expand Up @@ -265,7 +265,7 @@ fn load_config(path: &PathBuf) -> anyhow::Result<FormatterSettings> {
Ok(settings)
}

fn run_rustfmt(source: &str) -> String {
fn run_rustfmt(source: &str) -> Option<String> {
let mut child = process::Command::new("rustfmt")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand All @@ -280,5 +280,10 @@ fn run_rustfmt(source: &str) -> String {
.expect("failed to write to stdin");

let output = child.wait_with_output().expect("failed to read stdout");
String::from_utf8(output.stdout).expect("stdout is not valid utf8")

if output.status.success() {
Some(String::from_utf8(output.stdout).expect("stdout is not valid utf8"))
} else {
None
}
}

0 comments on commit adb98d2

Please sign in to comment.