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
2832macro_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+
4154pub mod alphabetical;
4255pub mod bins;
4356pub mod debug_artifacts;
0 commit comments