Make --explain subcommand return 1 for missing lints

This commit is contained in:
Martin Fischer 2023-06-16 11:11:20 +02:00
parent a94aac607c
commit 894d5dafac
2 changed files with 6 additions and 2 deletions

View File

@ -495,7 +495,7 @@ pub(crate) struct LintInfo {
explanation: &'static str,
}
pub fn explain(name: &str) {
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);
@ -512,8 +512,10 @@ pub fn explain(name: &str) {
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
}
}
0
} else {
println!("unknown lint: {name}");
1
}
}

View File

@ -57,7 +57,9 @@ pub fn main() {
if let Some(pos) = env::args().position(|a| a == "--explain") {
if let Some(mut lint) = env::args().nth(pos + 1) {
lint.make_ascii_lowercase();
clippy_lints::explain(&lint.strip_prefix("clippy::").unwrap_or(&lint).replace('-', "_"));
process::exit(clippy_lints::explain(
&lint.strip_prefix("clippy::").unwrap_or(&lint).replace('-', "_"),
));
} else {
show_help();
}