diff options
| author | bors <bors@rust-lang.org> | 2023-06-16 11:28:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-16 11:28:51 +0000 |
| commit | e11f36cc67aa19fdfdf022a2da4794b2435393ee (patch) | |
| tree | d4eec7b4d536ac17d56c71615f0e38d2eb0e4a1d | |
| parent | 43ecf8ea7d6c94dd5b0e17e7b64f0296bc80c615 (diff) | |
| parent | 894d5dafac8cb087a353047f33b4330c2a78cf2d (diff) | |
| download | rust-e11f36cc67aa19fdfdf022a2da4794b2435393ee.tar.gz rust-e11f36cc67aa19fdfdf022a2da4794b2435393ee.zip | |
Auto merge of #10965 - not-my-profile:explain-status, r=Alexendoo
Make `--explain` subcommand return 1 for missing lints changelog: The `--explain` subcommand now exits with the 1 exit code for missing lints
| -rw-r--r-- | clippy_lints/src/lib.rs | 37 | ||||
| -rw-r--r-- | src/main.rs | 4 |
2 files changed, 22 insertions, 19 deletions
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index b254c05d48b..f0a873b91eb 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -495,26 +495,27 @@ 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()); - match declared_lints::LINTS.iter().find(|info| info.lint.name == target) { - Some(info) => { - println!("{}", info.explanation); - // Check if the lint has configuration - let mdconf = get_configuration_metadata(); - if let Some(config_vec_positions) = mdconf - .iter() - .find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned())) - { - // If it has, print it - println!("### Configuration for {}:\n", info.lint.name_lower()); - for position in config_vec_positions { - let conf = &mdconf[position]; - println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default); - } + if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) { + println!("{}", info.explanation); + // Check if the lint has configuration + let mdconf = get_configuration_metadata(); + if let Some(config_vec_positions) = mdconf + .iter() + .find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned())) + { + // If it has, print it + println!("### Configuration for {}:\n", info.lint.name_lower()); + for position in config_vec_positions { + let conf = &mdconf[position]; + println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default); } - }, - None => println!("unknown lint: {name}"), + } + 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(); } |
