Skip to content

Commit e11f36c

Browse files
committed
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
2 parents 43ecf8e + 894d5da commit e11f36c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

clippy_lints/src/lib.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -495,26 +495,27 @@ pub(crate) struct LintInfo {
495495
explanation: &'static str,
496496
}
497497

498-
pub fn explain(name: &str) {
498+
pub fn explain(name: &str) -> i32 {
499499
let target = format!("clippy::{}", name.to_ascii_uppercase());
500-
match declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
501-
Some(info) => {
502-
println!("{}", info.explanation);
503-
// Check if the lint has configuration
504-
let mdconf = get_configuration_metadata();
505-
if let Some(config_vec_positions) = mdconf
506-
.iter()
507-
.find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned()))
508-
{
509-
// If it has, print it
510-
println!("### Configuration for {}:\n", info.lint.name_lower());
511-
for position in config_vec_positions {
512-
let conf = &mdconf[position];
513-
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
514-
}
500+
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
501+
println!("{}", info.explanation);
502+
// Check if the lint has configuration
503+
let mdconf = get_configuration_metadata();
504+
if let Some(config_vec_positions) = mdconf
505+
.iter()
506+
.find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned()))
507+
{
508+
// If it has, print it
509+
println!("### Configuration for {}:\n", info.lint.name_lower());
510+
for position in config_vec_positions {
511+
let conf = &mdconf[position];
512+
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
515513
}
516-
},
517-
None => println!("unknown lint: {name}"),
514+
}
515+
0
516+
} else {
517+
println!("unknown lint: {name}");
518+
1
518519
}
519520
}
520521

src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ pub fn main() {
5757
if let Some(pos) = env::args().position(|a| a == "--explain") {
5858
if let Some(mut lint) = env::args().nth(pos + 1) {
5959
lint.make_ascii_lowercase();
60-
clippy_lints::explain(&lint.strip_prefix("clippy::").unwrap_or(&lint).replace('-', "_"));
60+
process::exit(clippy_lints::explain(
61+
&lint.strip_prefix("clippy::").unwrap_or(&lint).replace('-', "_"),
62+
));
6163
} else {
6264
show_help();
6365
}

0 commit comments

Comments
 (0)