Skip to content

Commit

Permalink
Suppress --fmt --check diff if --quiet is passed (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 21, 2022
1 parent fbe1c4c commit 9887582
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9887582

Please sign in to comment.