diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-12-30 12:23:05 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-12-30 21:47:11 +0100 |
| commit | 75b3ee26cbeddcf2244e284d3c822d067cada2e2 (patch) | |
| tree | 5165ca83d0b39c542ebf681c13e38a62256f3363 /src | |
| parent | f9cc01126954e2fde28162fd83b4ef3e447526a6 (diff) | |
| download | rust-75b3ee26cbeddcf2244e284d3c822d067cada2e2.tar.gz rust-75b3ee26cbeddcf2244e284d3c822d067cada2e2.zip | |
Make tidy errors red
This makes it easier to see them (and makes people go owo).
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/tidy/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/lib.rs | 31 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index 97d038da702..fff83a1d097 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" } lazy_static = "1" walkdir = "2" ignore = "0.4.18" +termcolor = "1.1.3" [[bin]] name = "rust-tidy" diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 698e4850bea..ce7e7ac5cd4 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -3,6 +3,10 @@ //! This library contains the tidy lints and exposes it //! to be used by tools. +use std::fmt::Display; + +use termcolor::WriteColor; + /// A helper macro to `unwrap` a result except also print out details like: /// /// * The expression that failed @@ -26,18 +30,27 @@ macro_rules! t { } macro_rules! tidy_error { - ($bad:expr, $fmt:expr) => ({ - *$bad = true; - eprint!("tidy error: "); - eprintln!($fmt); - }); - ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ - *$bad = true; - eprint!("tidy error: "); - eprintln!($fmt, $($arg)*); + ($bad:expr, $($fmt:tt)*) => ({ + $crate::tidy_error($bad, format_args!($($fmt)*)).expect("failed to output error"); }); } +fn tidy_error(bad: &mut bool, args: impl Display) -> std::io::Result<()> { + use std::io::Write; + use termcolor::{Color, ColorChoice, ColorSpec, StandardStream}; + + *bad = true; + + let mut stderr = StandardStream::stdout(ColorChoice::Auto); + stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?; + + write!(&mut stderr, "tidy error")?; + stderr.set_color(&ColorSpec::new())?; + + writeln!(&mut stderr, ": {args}")?; + Ok(()) +} + pub mod alphabetical; pub mod bins; pub mod debug_artifacts; |
