Skip to content

Commit 75b3ee2

Browse files
committed
Make tidy errors red
This makes it easier to see them (and makes people go owo).
1 parent f9cc011 commit 75b3ee2

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

Cargo.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -2675,9 +2675,9 @@ dependencies = [
26752675

26762676
[[package]]
26772677
name = "owo-colors"
2678-
version = "3.4.0"
2678+
version = "3.5.0"
26792679
source = "registry+https://github.com./rust-lang/crates.io-index"
2680-
checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
2680+
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
26812681

26822682
[[package]]
26832683
name = "packed_simd_2"
@@ -5203,9 +5203,9 @@ dependencies = [
52035203

52045204
[[package]]
52055205
name = "termcolor"
5206-
version = "1.1.2"
5206+
version = "1.1.3"
52075207
source = "registry+https://github.com./rust-lang/crates.io-index"
5208-
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
5208+
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
52095209
dependencies = [
52105210
"winapi-util",
52115211
]
@@ -5309,6 +5309,7 @@ dependencies = [
53095309
"lazy_static",
53105310
"miropt-test-tools",
53115311
"regex",
5312+
"termcolor",
53125313
"walkdir",
53135314
]
53145315

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
1111
lazy_static = "1"
1212
walkdir = "2"
1313
ignore = "0.4.18"
14+
termcolor = "1.1.3"
1415

1516
[[bin]]
1617
name = "rust-tidy"

src/tools/tidy/src/lib.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
//! This library contains the tidy lints and exposes it
44
//! to be used by tools.
55
6+
use std::fmt::Display;
7+
8+
use termcolor::WriteColor;
9+
610
/// A helper macro to `unwrap` a result except also print out details like:
711
///
812
/// * The expression that failed
@@ -26,18 +30,27 @@ macro_rules! t {
2630
}
2731

2832
macro_rules! tidy_error {
29-
($bad:expr, $fmt:expr) => ({
30-
*$bad = true;
31-
eprint!("tidy error: ");
32-
eprintln!($fmt);
33-
});
34-
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
35-
*$bad = true;
36-
eprint!("tidy error: ");
37-
eprintln!($fmt, $($arg)*);
33+
($bad:expr, $($fmt:tt)*) => ({
34+
$crate::tidy_error($bad, format_args!($($fmt)*)).expect("failed to output error");
3835
});
3936
}
4037

38+
fn tidy_error(bad: &mut bool, args: impl Display) -> std::io::Result<()> {
39+
use std::io::Write;
40+
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream};
41+
42+
*bad = true;
43+
44+
let mut stderr = StandardStream::stdout(ColorChoice::Auto);
45+
stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
46+
47+
write!(&mut stderr, "tidy error")?;
48+
stderr.set_color(&ColorSpec::new())?;
49+
50+
writeln!(&mut stderr, ": {args}")?;
51+
Ok(())
52+
}
53+
4154
pub mod alphabetical;
4255
pub mod bins;
4356
pub mod debug_artifacts;

0 commit comments

Comments
 (0)