When I run "cargo clippy — -W clippy::pedantic" on the code below I get the message:
note: `-W clippy::struct-excessive-bools` implied by `-W clippy::pedantic`
help: consider using a state machine or refactoring bools into two-variant enums
help: for further information visit https://rust-lang.github.io/rust clippy/master/index.html#struct_excessive_bool
I have tried to disable this with #[allow(clippy::clippy::struct-excessive-bools)] but that fails:
5 | #[allow(clippy::clippy::struct-excessive-bools)]
| ^^^^^^ expected identifier, found keyword
Is using #[allow(clippy::clippy::pedantic)] the only solution?
”’
use clap::Parser;
#[derive(Parser, Default, Debug)]
#[clap(version, about)]
#[allow(clippy::clippy::struct-excessive-bools)]
struct Arguments {
#[clap(short, long)]
/// Set aaa
aaa: bool,
#[clap(short, long)]
/// Set bbb
bbb: bool,
#[clap(short, long)]
/// Set ccc
ccc: bool,
#[clap(short, long)]
/// Set ddd
ddd: bool,
}
fn main() {
let args = Arguments::parse();
dbg!(args);
}
”’
>Solution :
The lint is named clippy::struct_excessive_bools, with underscores instead of hyphens; and it doesn’t need additional namespacing. #[allow(clippy::struct_excessive_bools)] works – run Clippy with the "Tools" button at the top-right corner with and without the attribute to see.