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};
7 let matches = get_clap_config();
9 match matches.subcommand() {
10 ("bless", Some(matches)) => {
11 bless::bless(matches.is_present("ignore-timestamp"));
13 ("fmt", Some(matches)) => {
14 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
16 ("update_lints", Some(matches)) => {
17 if matches.is_present("print-only") {
18 update_lints::print_lints();
19 } else if matches.is_present("check") {
20 update_lints::run(update_lints::UpdateMode::Check);
22 update_lints::run(update_lints::UpdateMode::Change);
25 ("new_lint", Some(matches)) => {
26 match new_lint::create(
27 matches.value_of("pass"),
28 matches.value_of("name"),
29 matches.value_of("category"),
31 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
32 Err(e) => eprintln!("Unable to create lint: {}", e),
35 ("limit_stderr_length", _) => {
36 stderr_length_check::check();
38 ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
39 ("serve", Some(matches)) => {
40 let port = matches.value_of("port").unwrap().parse().unwrap();
41 let lint = matches.value_of("lint");
42 serve::run(port, lint);
48 fn get_clap_config<'a>() -> ArgMatches<'a> {
49 App::new("Clippy developer tooling")
51 SubCommand::with_name("bless")
52 .about("bless the test output changes")
54 Arg::with_name("ignore-timestamp")
55 .long("ignore-timestamp")
56 .help("Include files updated before clippy was built"),
60 SubCommand::with_name("fmt")
61 .about("Run rustfmt on all projects and tests")
63 Arg::with_name("check")
65 .help("Use the rustfmt --check option"),
68 Arg::with_name("verbose")
71 .help("Echo commands run"),
75 SubCommand::with_name("update_lints")
76 .about("Updates lint registration and information from the source code")
79 * the lint count in README.md is correct\n \
80 * the changelog contains markdown link references at the bottom\n \
81 * all lint groups include the correct lints\n \
82 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
83 * all lints are registered in the lint store",
85 .arg(Arg::with_name("print-only").long("print-only").help(
86 "Print a table of lints to STDOUT. \
87 This does not include deprecated and internal lints. \
88 (Does not modify any files)",
91 Arg::with_name("check")
93 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
97 SubCommand::with_name("new_lint")
98 .about("Create new lint and run `cargo dev update_lints`")
100 Arg::with_name("pass")
103 .help("Specify whether the lint runs during the early or late pass")
105 .possible_values(&["early", "late"])
109 Arg::with_name("name")
112 .help("Name of the new lint in snake case, ex: fn_too_long")
117 Arg::with_name("category")
120 .help("What category the lint belongs to")
121 .default_value("nursery")
138 SubCommand::with_name("limit_stderr_length")
139 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
142 SubCommand::with_name("ra_setup")
143 .about("Alter dependencies so rust-analyzer can find rustc internals")
145 Arg::with_name("rustc-repo-path")
148 .help("The path to a rustc repo that will be used for setting the dependencies")
155 SubCommand::with_name("serve")
156 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
158 Arg::with_name("port")
161 .help("Local port for the http server")
162 .default_value("8000")
163 .validator_os(serve::validate_port),
165 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),