Skip to content

Commit 81808b7

Browse files
Rollup merge of #106286 - Nilstrieb:tidy-cowows, r=jyn514
Make tidy errors red This makes it easier to see them (and makes people go owo). I also changes the error codes check to not print too many things and use `tidy_error`. r? ```@jyn514```
2 parents 5b74a33 + 75b3ee2 commit 81808b7

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
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/error_codes_check.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
8080
ignore_found
8181
}
8282

83-
macro_rules! some_or_continue {
84-
($e:expr) => {
85-
match $e {
86-
Some(e) => e,
87-
None => continue,
88-
}
89-
};
90-
}
91-
9283
fn extract_error_codes(
9384
f: &str,
9485
error_codes: &mut HashMap<String, ErrorCodeStatus>,
@@ -122,10 +113,16 @@ fn extract_error_codes(
122113
Some((file_name, _)) => file_name,
123114
},
124115
};
125-
let path = some_or_continue!(path.parent())
116+
117+
let Some(parent) = path.parent() else {
118+
continue;
119+
};
120+
121+
let path = parent
126122
.join(md_file_name)
127123
.canonicalize()
128124
.expect("failed to canonicalize error explanation file path");
125+
129126
match read_to_string(&path) {
130127
Ok(content) => {
131128
let has_test = check_if_error_code_is_test_in_explanation(&content, &err_code);
@@ -215,8 +212,6 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
215212
// * #[error = "E0111"]
216213
let regex = Regex::new(r#"[(,"\s](E\d{4})[,)"]"#).unwrap();
217214

218-
println!("Checking which error codes lack tests...");
219-
220215
for path in paths {
221216
walk(path, &mut filter_dirs, &mut |entry, contents| {
222217
let file_name = entry.file_name();
@@ -245,20 +240,15 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
245240
});
246241
}
247242
if found_explanations == 0 {
248-
eprintln!("No error code explanation was tested!");
249-
*bad = true;
243+
tidy_error!(bad, "No error code explanation was tested!");
250244
}
251245
if found_tests == 0 {
252-
eprintln!("No error code was found in compilation errors!");
253-
*bad = true;
246+
tidy_error!(bad, "No error code was found in compilation errors!");
254247
}
255248
if explanations.is_empty() {
256-
eprintln!("No error code explanation was found!");
257-
*bad = true;
249+
tidy_error!(bad, "No error code explanation was found!");
258250
}
259251
if errors.is_empty() {
260-
println!("Found {} error codes", error_codes.len());
261-
262252
for (err_code, error_status) in &error_codes {
263253
if !error_status.has_test && !EXEMPTED_FROM_TEST.contains(&err_code.as_str()) {
264254
errors.push(format!("Error code {err_code} needs to have at least one UI test!"));
@@ -310,11 +300,6 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
310300
}
311301
errors.sort();
312302
for err in &errors {
313-
eprintln!("{err}");
314-
}
315-
println!("Found {} error(s) in error codes", errors.len());
316-
if !errors.is_empty() {
317-
*bad = true;
303+
tidy_error!(bad, "{err}");
318304
}
319-
println!("Done!");
320305
}

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)