From 894d5dafac8cb087a353047f33b4330c2a78cf2d Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 16 Jun 2023 11:11:20 +0200 Subject: [PATCH] Make `--explain` subcommand return 1 for missing lints --- clippy_lints/src/lib.rs | 4 +++- src/main.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index cd1b63bdba2..f0a873b91eb 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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 } } diff --git a/src/main.rs b/src/main.rs index 188ff87abfc..300c84a1442 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); }