2019-11-25 17:23:48 +01:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
2021-05-20 12:30:31 +02:00
|
|
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2019-11-25 17:23:48 +01:00
|
|
|
|
2020-12-20 17:19:49 +01:00
|
|
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
2021-03-25 19:29:11 +01:00
|
|
|
use clippy_dev::{bless, fmt, ide_setup, new_lint, serve, stderr_length_check, update_lints};
|
2018-07-17 22:50:17 +02:00
|
|
|
fn main() {
|
2020-12-20 17:19:49 +01:00
|
|
|
let matches = get_clap_config();
|
|
|
|
|
|
|
|
match matches.subcommand() {
|
2021-01-15 10:56:44 +01:00
|
|
|
("bless", Some(matches)) => {
|
|
|
|
bless::bless(matches.is_present("ignore-timestamp"));
|
2020-12-20 17:19:49 +01:00
|
|
|
},
|
|
|
|
("fmt", Some(matches)) => {
|
|
|
|
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
|
|
|
|
},
|
|
|
|
("update_lints", Some(matches)) => {
|
|
|
|
if matches.is_present("print-only") {
|
|
|
|
update_lints::print_lints();
|
|
|
|
} else if matches.is_present("check") {
|
|
|
|
update_lints::run(update_lints::UpdateMode::Check);
|
|
|
|
} else {
|
|
|
|
update_lints::run(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::run(update_lints::UpdateMode::Change),
|
|
|
|
Err(e) => eprintln!("Unable to create lint: {}", e),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
("limit_stderr_length", _) => {
|
|
|
|
stderr_length_check::check();
|
|
|
|
},
|
2021-03-25 19:29:11 +01:00
|
|
|
("ide_setup", Some(matches)) => ide_setup::run(matches.value_of("rustc-repo-path")),
|
2020-12-20 17:19:49 +01:00
|
|
|
("serve", Some(matches)) => {
|
|
|
|
let port = matches.value_of("port").unwrap().parse().unwrap();
|
|
|
|
let lint = matches.value_of("lint");
|
|
|
|
serve::run(port, lint);
|
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_clap_config<'a>() -> ArgMatches<'a> {
|
2021-03-12 15:30:50 +01:00
|
|
|
App::new("Clippy developer tooling")
|
2021-01-15 10:56:44 +01:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("bless")
|
|
|
|
.about("bless the test output changes")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ignore-timestamp")
|
|
|
|
.long("ignore-timestamp")
|
|
|
|
.help("Include files updated before clippy was built"),
|
|
|
|
),
|
|
|
|
)
|
2019-06-25 06:43:38 +02:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("fmt")
|
|
|
|
.about("Run rustfmt on all projects and tests")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
|
|
|
.help("Use the rustfmt --check option"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("verbose")
|
|
|
|
.short("v")
|
|
|
|
.long("verbose")
|
|
|
|
.help("Echo commands run"),
|
|
|
|
),
|
|
|
|
)
|
2018-07-17 22:50:17 +02:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("update_lints")
|
2019-03-08 07:45:31 +02:00
|
|
|
.about("Updates lint registration and information from the source code")
|
|
|
|
.long_about(
|
2018-11-27 21:13:08 +01:00
|
|
|
"Makes sure that:\n \
|
2020-12-20 17:19:49 +01:00
|
|
|
* the lint count in README.md is correct\n \
|
|
|
|
* the changelog contains markdown link references at the bottom\n \
|
|
|
|
* all lint groups include the correct lints\n \
|
|
|
|
* lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
|
|
|
|
* all lints are registered in the lint store",
|
2018-11-04 09:41:28 +01:00
|
|
|
)
|
2018-11-27 21:13:08 +01:00
|
|
|
.arg(Arg::with_name("print-only").long("print-only").help(
|
|
|
|
"Print a table of lints to STDOUT. \
|
2020-12-20 17:19:49 +01:00
|
|
|
This does not include deprecated and internal lints. \
|
|
|
|
(Does not modify any files)",
|
2018-11-27 21:13:08 +01:00
|
|
|
))
|
2018-11-04 09:41:28 +01:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
2020-01-30 08:33:48 +01:00
|
|
|
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
|
2018-11-27 21:13:08 +01:00
|
|
|
),
|
|
|
|
)
|
2019-12-31 18:07:39 -07:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("new_lint")
|
2020-01-30 08:33:48 +01:00
|
|
|
.about("Create new lint and run `cargo dev update_lints`")
|
2019-12-31 18:07:39 -07:00
|
|
|
.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),
|
|
|
|
),
|
|
|
|
)
|
2020-03-31 15:13:38 +02:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("limit_stderr_length")
|
|
|
|
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
|
2019-05-16 07:31:56 +02:00
|
|
|
)
|
2020-06-09 14:36:01 +00:00
|
|
|
.subcommand(
|
2021-03-25 19:29:11 +01:00
|
|
|
SubCommand::with_name("ide_setup")
|
|
|
|
.about("Alter dependencies so Intellij Rust can find rustc internals")
|
2020-06-09 14:36:01 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("rustc-repo-path")
|
|
|
|
.long("repo-path")
|
|
|
|
.short("r")
|
|
|
|
.help("The path to a rustc repo that will be used for setting the dependencies")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("path")
|
|
|
|
.required(true),
|
|
|
|
),
|
|
|
|
)
|
2020-10-09 12:45:29 +02:00
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("serve")
|
|
|
|
.about("Launch a local 'ALL the Clippy Lints' website in a browser")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("port")
|
|
|
|
.long("port")
|
|
|
|
.short("p")
|
|
|
|
.help("Local port for the http server")
|
|
|
|
.default_value("8000")
|
|
|
|
.validator_os(serve::validate_port),
|
|
|
|
)
|
|
|
|
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
|
2021-03-12 15:30:50 +01:00
|
|
|
)
|
|
|
|
.get_matches()
|
2018-07-17 22:50:17 +02:00
|
|
|
}
|