1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
2 #![warn(rust_2018_idioms, unused_lifetimes)]
5 use std::path::PathBuf;
12 bad_lines: Vec<String>,
16 fn new(path: PathBuf) -> Self {
17 let content: String = std::fs::read_to_string(&path).unwrap();
18 // we don't want the first letter after "error: ", "help: " ... to be capitalized
19 // also no punctuation (except for "?" ?) at the end of a line
20 let regex_set: RegexSet = RegexSet::new(&[
34 // sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
35 // we want to ask a question ending in "?"
36 let exceptions_set: RegexSet = RegexSet::new(&[
37 r".*C-like enum variant discriminant is not portable to 32-bit targets",
38 r".*did you mean `unix`?",
39 r".*the arguments may be inverted...",
40 r".*Intel x86 assembly syntax used",
41 r".*AT&T x86 assembly syntax used",
42 r".*remove .*the return type...",
43 r"note: Clippy version: .*",
44 r"the compiler unexpectedly panicked. this is a bug.",
48 let bad_lines = content
50 .filter(|line| regex_set.matches(line).matched_any())
52 .filter(|line| !exceptions_set.matches(line).matched_any())
53 .map(ToOwned::to_owned)
54 .collect::<Vec<String>>();
56 Message { path, bad_lines }
61 fn lint_message_convention() {
62 // disable the test inside the rustc test suite
63 if option_env!("RUSTC_TEST_SUITE").is_some() {
67 // make sure that lint messages:
68 // * are not capitalized
69 // * don't have punctuation at the end of the last sentence
71 // these directories have interesting tests
72 let test_dirs = ["ui", "ui-cargo", "ui-internal", "ui-toml"]
76 let base = PathBuf::from("tests");
80 // gather all .stderr files
83 std::fs::read_dir(dir)
84 .expect("failed to read dir")
85 .map(|direntry| direntry.unwrap().path())
87 .filter(|file| matches!(file.extension().map(OsStr::to_str), Some(Some("stderr"))));
89 // get all files that have any "bad lines" in them
90 let bad_tests: Vec<Message> = tests
92 .filter(|message| !message.bad_lines.is_empty())
95 for message in &bad_tests {
97 "error: the test '{}' contained the following nonconforming lines :",
98 message.path.display()
100 message.bad_lines.iter().for_each(|line| eprintln!("{}", line));
105 "\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."
107 eprintln!("Check out the rustc-dev-guide for more information:");
108 eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");
110 assert!(bad_tests.is_empty());