From 9887582497cc07be6f5028ba82d63339188a2209 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 20 Dec 2022 20:57:58 -0800 Subject: [PATCH] Suppress --fmt --check diff if --quiet is passed (#1457) --- src/subcommand.rs | 32 +++++++++++++++++--------------- tests/fmt.rs | 8 ++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 449f100976..be36912b56 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -374,21 +374,23 @@ impl Subcommand { return if formatted == src { Ok(()) } else { - use similar::{ChangeTag, TextDiff}; - - let diff = TextDiff::configure() - .algorithm(similar::Algorithm::Patience) - .diff_lines(src, &formatted); - - for op in diff.ops() { - for change in diff.iter_changes(op) { - let (symbol, color) = match change.tag() { - ChangeTag::Delete => ("-", config.color.stderr().diff_deleted()), - ChangeTag::Equal => (" ", config.color.stderr()), - ChangeTag::Insert => ("+", config.color.stderr().diff_added()), - }; - - eprint!("{}{symbol}{change}{}", color.prefix(), color.suffix()); + if !config.verbosity.quiet() { + use similar::{ChangeTag, TextDiff}; + + let diff = TextDiff::configure() + .algorithm(similar::Algorithm::Patience) + .diff_lines(src, &formatted); + + for op in diff.ops() { + for change in diff.iter_changes(op) { + let (symbol, color) = match change.tag() { + ChangeTag::Delete => ("-", config.color.stderr().diff_deleted()), + ChangeTag::Equal => (" ", config.color.stderr()), + ChangeTag::Insert => ("+", config.color.stderr().diff_added()), + }; + + eprint!("{}{symbol}{change}{}", color.prefix(), color.suffix()); + } } } diff --git a/tests/fmt.rs b/tests/fmt.rs index 348cb27fab..3c972eda80 100644 --- a/tests/fmt.rs +++ b/tests/fmt.rs @@ -53,6 +53,14 @@ test! { status: EXIT_FAILURE, } +test! { + name: check_found_diff_quiet, + justfile: "x:=``\n", + args: ("--unstable", "--fmt", "--check", "--quiet"), + stderr: "", + status: EXIT_FAILURE, +} + test! { name: check_diff_color, justfile: "x:=``\n",