1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 use clap::{App, Arg, ArgMatches, SubCommand};
4 use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
6 let matches = get_clap_config();
8 match matches.subcommand() {
9 ("bless", Some(matches)) => {
10 bless::bless(matches.is_present("ignore-timestamp"));
12 ("fmt", Some(matches)) => {
13 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
15 ("update_lints", Some(matches)) => {
16 if matches.is_present("print-only") {
17 update_lints::print_lints();
18 } else if matches.is_present("check") {
19 update_lints::run(update_lints::UpdateMode::Check);
21 update_lints::run(update_lints::UpdateMode::Change);
24 ("new_lint", Some(matches)) => {
25 match new_lint::create(
26 matches.value_of("pass"),
27 matches.value_of("name"),
28 matches.value_of("category"),
30 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
31 Err(e) => eprintln!("Unable to create lint: {}", e),
34 ("limit_stderr_length", _) => {
35 stderr_length_check::check();
37 ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
38 ("serve", Some(matches)) => {
39 let port = matches.value_of("port").unwrap().parse().unwrap();
40 let lint = matches.value_of("lint");
41 serve::run(port, lint);
47 fn get_clap_config<'a>() -> ArgMatches<'a> {
48 App::new("Clippy developer tooling")
50 SubCommand::with_name("bless")
51 .about("bless the test output changes")
53 Arg::with_name("ignore-timestamp")
54 .long("ignore-timestamp")
55 .help("Include files updated before clippy was built"),
59 SubCommand::with_name("fmt")
60 .about("Run rustfmt on all projects and tests")
62 Arg::with_name("check")
64 .help("Use the rustfmt --check option"),
67 Arg::with_name("verbose")
70 .help("Echo commands run"),
74 SubCommand::with_name("update_lints")
75 .about("Updates lint registration and information from the source code")
78 * the lint count in README.md is correct\n \
79 * the changelog contains markdown link references at the bottom\n \
80 * all lint groups include the correct lints\n \
81 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
82 * all lints are registered in the lint store",
84 .arg(Arg::with_name("print-only").long("print-only").help(
85 "Print a table of lints to STDOUT. \
86 This does not include deprecated and internal lints. \
87 (Does not modify any files)",
90 Arg::with_name("check")
92 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
96 SubCommand::with_name("new_lint")
97 .about("Create new lint and run `cargo dev update_lints`")
99 Arg::with_name("pass")
102 .help("Specify whether the lint runs during the early or late pass")
104 .possible_values(&["early", "late"])
108 Arg::with_name("name")
111 .help("Name of the new lint in snake case, ex: fn_too_long")
116 Arg::with_name("category")
119 .help("What category the lint belongs to")
120 .default_value("nursery")
137 SubCommand::with_name("limit_stderr_length")
138 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
141 SubCommand::with_name("ra_setup")
142 .about("Alter dependencies so rust-analyzer can find rustc internals")
144 Arg::with_name("rustc-repo-path")
147 .help("The path to a rustc repo that will be used for setting the dependencies")
154 SubCommand::with_name("serve")
155 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
157 Arg::with_name("port")
160 .help("Local port for the http server")
161 .default_value("8000")
162 .validator_os(serve::validate_port),
164 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),