Generate new lints easily

- Add option in clippy_dev to automatically generate boilerplate
  code for adding new lints
This commit is contained in:
Brad Sherman
2019-12-31 18:07:39 -07:00
parent be09bb47db
commit ea82cbe790
2 changed files with 234 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ use clap::{App, Arg, SubCommand};
use clippy_dev::*;
mod fmt;
mod new_lint;
mod stderr_length_check;
#[derive(PartialEq)]
@@ -51,6 +52,47 @@ fn main() {
.help("Checks that util/dev update_lints has been run. Used on CI."),
),
)
.subcommand(
SubCommand::with_name("new_lint")
.about("Create new lint and run util/dev update_lints")
.arg(
Arg::with_name("pass")
.short("p")
.long("pass")
.help("Specify whether the lint runs during the early or late pass")
.takes_value(true)
.possible_values(&["early", "late"])
.required(true),
)
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.help("Name of the new lint in snake case, ex: fn_too_long")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("category")
.short("c")
.long("category")
.help("What category the lint belongs to")
.default_value("nursery")
.possible_values(&[
"style",
"correctness",
"complexity",
"perf",
"pedantic",
"restriction",
"cargo",
"nursery",
"internal",
"internal_warn",
])
.takes_value(true),
),
)
.arg(
Arg::with_name("limit-stderr-length")
.long("limit-stderr-length")
@@ -75,6 +117,16 @@ fn main() {
update_lints(&UpdateMode::Change);
}
},
("new_lint", Some(matches)) => {
match new_lint::create(
matches.value_of("pass"),
matches.value_of("name"),
matches.value_of("category"),
) {
Ok(_) => update_lints(&UpdateMode::Change),
Err(e) => eprintln!("Unable to create lint: {}", e),
}
},
_ => {},
}
}