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
This commit is contained in:
commit
e11f36cc67
@ -495,26 +495,27 @@ pub(crate) struct LintInfo {
|
|||||||
explanation: &'static str,
|
explanation: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn explain(name: &str) {
|
pub fn explain(name: &str) -> i32 {
|
||||||
let target = format!("clippy::{}", name.to_ascii_uppercase());
|
let target = format!("clippy::{}", name.to_ascii_uppercase());
|
||||||
match declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
|
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
|
||||||
Some(info) => {
|
println!("{}", info.explanation);
|
||||||
println!("{}", info.explanation);
|
// Check if the lint has configuration
|
||||||
// Check if the lint has configuration
|
let mdconf = get_configuration_metadata();
|
||||||
let mdconf = get_configuration_metadata();
|
if let Some(config_vec_positions) = mdconf
|
||||||
if let Some(config_vec_positions) = mdconf
|
.iter()
|
||||||
.iter()
|
.find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned()))
|
||||||
.find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned()))
|
{
|
||||||
{
|
// If it has, print it
|
||||||
// If it has, print it
|
println!("### Configuration for {}:\n", info.lint.name_lower());
|
||||||
println!("### Configuration for {}:\n", info.lint.name_lower());
|
for position in config_vec_positions {
|
||||||
for position in config_vec_positions {
|
let conf = &mdconf[position];
|
||||||
let conf = &mdconf[position];
|
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
|
||||||
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => println!("unknown lint: {name}"),
|
0
|
||||||
|
} else {
|
||||||
|
println!("unknown lint: {name}");
|
||||||
|
1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,9 @@ pub fn main() {
|
|||||||
if let Some(pos) = env::args().position(|a| a == "--explain") {
|
if let Some(pos) = env::args().position(|a| a == "--explain") {
|
||||||
if let Some(mut lint) = env::args().nth(pos + 1) {
|
if let Some(mut lint) = env::args().nth(pos + 1) {
|
||||||
lint.make_ascii_lowercase();
|
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 {
|
} else {
|
||||||
show_help();
|
show_help();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user