mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Move tag removing to --explain
This commit is contained in:
parent
4997ee7afc
commit
0735031be9
1 changed files with 21 additions and 1 deletions
|
@ -524,8 +524,28 @@ impl LintInfo {
|
|||
|
||||
pub fn explain(name: &str) -> i32 {
|
||||
let target = format!("clippy::{}", name.to_ascii_uppercase());
|
||||
|
||||
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
|
||||
println!("{}", info.explanation);
|
||||
// Remove tags and hidden code:
|
||||
let mut explanation = String::with_capacity(128);
|
||||
let mut in_code = false;
|
||||
for line in info.explanation.lines().map(|line| line.trim()) {
|
||||
if let Some(lang) = line.strip_prefix("```") {
|
||||
let tag = lang.split_once(',').map_or(lang, |(left, _)| left);
|
||||
if !in_code && matches!(tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail") {
|
||||
explanation += "```rust\n";
|
||||
} else {
|
||||
explanation += line;
|
||||
explanation.push('\n');
|
||||
}
|
||||
in_code = !in_code;
|
||||
} else if !(in_code && line.starts_with("# ")) {
|
||||
explanation += line;
|
||||
explanation.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", explanation);
|
||||
// Check if the lint has configuration
|
||||
let mut mdconf = get_configuration_metadata();
|
||||
let name = name.to_ascii_lowercase();
|
||||
|
|
Loading…
Reference in a new issue