Make --explain
subcommand return 1 for missing lints
This commit is contained in:
parent
a94aac607c
commit
894d5dafac
@ -495,7 +495,7 @@ 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());
|
||||||
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
|
if let Some(info) = declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
|
||||||
println!("{}", info.explanation);
|
println!("{}", info.explanation);
|
||||||
@ -512,8 +512,10 @@ pub fn explain(name: &str) {
|
|||||||
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
|
println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
|
||||||
} else {
|
} else {
|
||||||
println!("unknown lint: {name}");
|
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