Skip to content

Commit 0735031

Browse files
committed
Move tag removing to --explain
1 parent 4997ee7 commit 0735031

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

clippy_lints/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,28 @@ impl LintInfo {
524524

525525
pub fn explain(name: &str) -> i32 {
526526
let target = format!("clippy::{}", name.to_ascii_uppercase());
527+
527528
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
528-
println!("{}", info.explanation);
529+
// Remove tags and hidden code:
530+
let mut explanation = String::with_capacity(128);
531+
let mut in_code = false;
532+
for line in info.explanation.lines().map(|line| line.trim()) {
533+
if let Some(lang) = line.strip_prefix("```") {
534+
let tag = lang.split_once(',').map_or(lang, |(left, _)| left);
535+
if !in_code && matches!(tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail") {
536+
explanation += "```rust\n";
537+
} else {
538+
explanation += line;
539+
explanation.push('\n');
540+
}
541+
in_code = !in_code;
542+
} else if !(in_code && line.starts_with("# ")) {
543+
explanation += line;
544+
explanation.push('\n');
545+
}
546+
}
547+
548+
println!("{}", explanation);
529549
// Check if the lint has configuration
530550
let mut mdconf = get_configuration_metadata();
531551
let name = name.to_ascii_lowercase();

0 commit comments

Comments
 (0)