Skip to content

Commit

Permalink
Auto merge of rust-lang#10965 - not-my-profile:explain-status, r=Alex…
Browse files Browse the repository at this point in the history
…endoo

Make `--explain` subcommand return 1 for missing lints

changelog: The `--explain` subcommand now exits with the 1 exit code for missing lints
  • Loading branch information
bors committed Jun 16, 2023
2 parents 43ecf8e + 894d5da commit e11f36c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
37 changes: 19 additions & 18 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit e11f36c

Please sign in to comment.