Detect unstable lint docs that dont enable their feature
This commit is contained in:
parent
e7ad3ae331
commit
9cbd17778a
1 changed files with 28 additions and 10 deletions
|
|
@ -480,26 +480,44 @@ impl<'a> LintExtractor<'a> {
|
|||
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
|
||||
.collect();
|
||||
if matches.is_empty() {
|
||||
// Some lints override their code to something else (E0566).
|
||||
// Try to find something that looks like it could be our lint.
|
||||
let matches: Vec<_> = msgs.iter().filter(|msg|
|
||||
matches!(&msg["rendered"], serde_json::Value::String(s) if s.contains(name)))
|
||||
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
|
||||
.collect();
|
||||
if matches.is_empty() {
|
||||
// Try to detect if an unstable lint forgot to enable a `#![feature(..)]`.
|
||||
if name != "test_unstable_lint" && msgs.iter().any(|msg| {
|
||||
matches!(&msg["code"]["code"], serde_json::Value::String(s) if s=="unknown_lints")
|
||||
&& matches!(&msg["message"], serde_json::Value::String(s) if s.contains(name))
|
||||
}) {
|
||||
let rendered: Vec<&str> =
|
||||
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
|
||||
let non_json: Vec<&str> =
|
||||
stderr.lines().filter(|line| !line.starts_with('{')).collect();
|
||||
Err(format!(
|
||||
"did not find lint `{}` in output of example, got:\n{}\n{}",
|
||||
"lint `{}` is unstable and must be enabled in example. see:\n{}\n{}",
|
||||
name,
|
||||
rendered.join("\n"),
|
||||
non_json.join("\n"),
|
||||
rendered.join("\n")
|
||||
)
|
||||
.into())
|
||||
} else {
|
||||
Ok(matches.join("\n"))
|
||||
// Some lints override their code to something else (E0566).
|
||||
// Try to find something that looks like it could be our lint.
|
||||
let matches: Vec<_> = msgs.iter().filter(|msg|
|
||||
matches!(&msg["rendered"], serde_json::Value::String(s) if s.contains(name)))
|
||||
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
|
||||
.collect();
|
||||
if matches.is_empty() {
|
||||
let rendered: Vec<&str> =
|
||||
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
|
||||
let non_json: Vec<&str> =
|
||||
stderr.lines().filter(|line| !line.starts_with('{')).collect();
|
||||
Err(format!(
|
||||
"did not find lint `{}` in output of example, got:\n{}\n{}",
|
||||
name,
|
||||
non_json.join("\n"),
|
||||
rendered.join("\n")
|
||||
)
|
||||
.into())
|
||||
} else {
|
||||
Ok(matches.join("\n"))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Ok(matches.join("\n"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue