2 use std::path::PathBuf;
9 bad_lines: Vec<String>,
13 fn new(path: PathBuf) -> Self {
14 let content: String = std::fs::read_to_string(&path).unwrap();
15 // we don't want the first letter after "error: ", "help: " ... to be capitalized
16 // also no puncutation (except for "?" ?) at the end of a line
17 let regex_set: RegexSet = RegexSet::new(&[
31 // sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
32 // we want to ask a question ending in "?"
33 let exceptions_set: RegexSet = RegexSet::new(&[
34 r".*C-like enum variant discriminant is not portable to 32-bit targets",
35 r".*did you mean `unix`?",
36 r".*the arguments may be inverted...",
37 r".*Intel x86 assembly syntax used",
38 r".*AT&T x86 assembly syntax used",
39 r".*remove .*the return type...",
40 r"note: Clippy version: .*",
41 r"the compiler unexpectedly panicked. this is a bug.",
45 let bad_lines = content
47 .filter(|line| regex_set.matches(line).matched_any())
49 .filter(|line| !exceptions_set.matches(line).matched_any())
50 .map(ToOwned::to_owned)
51 .collect::<Vec<String>>();
53 Message { path, bad_lines }
58 fn lint_message_convention() {
59 // disable the test inside the rustc test suite
60 if option_env!("RUSTC_TEST_SUITE").is_some() {
64 // make sure that lint messages:
65 // * are not capitalized
66 // * don't have puncuation at the end of the last sentence
68 // these directories have interesting tests
69 let test_dirs = ["ui", "ui-cargo", "ui-internal", "ui-toml"]
73 let base = PathBuf::from("tests");
77 // gather all .stderr files
80 std::fs::read_dir(dir)
81 .expect("failed to read dir")
82 .map(|direntry| direntry.unwrap().path())
84 .filter(|file| matches!(file.extension().map(OsStr::to_str), Some(Some("stderr"))));
86 // get all files that have any "bad lines" in them
87 let bad_tests: Vec<Message> = tests
89 .filter(|message| !message.bad_lines.is_empty())
92 bad_tests.iter().for_each(|message| {
94 "error: the test '{}' contained the following nonconforming lines :",
95 message.path.display()
97 message.bad_lines.iter().for_each(|line| eprintln!("{}", line));
102 "\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed."
104 eprintln!("Check out the rustc-dev-guide for more information:");
105 eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");
107 assert!(bad_tests.is_empty());