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 #[cfg(feature = "lintcheck")]
7 use clippy_dev::lintcheck;
10 let matches = get_clap_config();
12 match matches.subcommand() {
13 ("bless", Some(matches)) => {
14 bless::bless(matches.is_present("ignore-timestamp"));
16 #[cfg(feature = "lintcheck")]
17 ("lintcheck", Some(matches)) => {
18 lintcheck::run(&matches);
20 ("fmt", Some(matches)) => {
21 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
23 ("update_lints", Some(matches)) => {
24 if matches.is_present("print-only") {
25 update_lints::print_lints();
26 } else if matches.is_present("check") {
27 update_lints::run(update_lints::UpdateMode::Check);
29 update_lints::run(update_lints::UpdateMode::Change);
32 ("new_lint", Some(matches)) => {
33 match new_lint::create(
34 matches.value_of("pass"),
35 matches.value_of("name"),
36 matches.value_of("category"),
38 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
39 Err(e) => eprintln!("Unable to create lint: {}", e),
42 ("limit_stderr_length", _) => {
43 stderr_length_check::check();
45 ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
46 ("serve", Some(matches)) => {
47 let port = matches.value_of("port").unwrap().parse().unwrap();
48 let lint = matches.value_of("lint");
49 serve::run(port, lint);
55 fn get_clap_config<'a>() -> ArgMatches<'a> {
56 #[cfg(feature = "lintcheck")]
57 let lintcheck_sbcmd = SubCommand::with_name("lintcheck")
58 .about("run clippy on a set of crates and check output")
60 Arg::with_name("only")
64 .help("only process a single crate of the list"),
67 Arg::with_name("crates-toml")
69 .value_name("CRATES-SOURCES-TOML-PATH")
71 .help("set the path for a crates.toml where lintcheck should read the sources from"),
74 Arg::with_name("threads")
79 .help("number of threads to use, 0 automatic choice"),
82 let app = App::new("Clippy developer tooling")
84 SubCommand::with_name("bless")
85 .about("bless the test output changes")
87 Arg::with_name("ignore-timestamp")
88 .long("ignore-timestamp")
89 .help("Include files updated before clippy was built"),
93 SubCommand::with_name("fmt")
94 .about("Run rustfmt on all projects and tests")
96 Arg::with_name("check")
98 .help("Use the rustfmt --check option"),
101 Arg::with_name("verbose")
104 .help("Echo commands run"),
108 SubCommand::with_name("update_lints")
109 .about("Updates lint registration and information from the source code")
111 "Makes sure that:\n \
112 * the lint count in README.md is correct\n \
113 * the changelog contains markdown link references at the bottom\n \
114 * all lint groups include the correct lints\n \
115 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
116 * all lints are registered in the lint store",
118 .arg(Arg::with_name("print-only").long("print-only").help(
119 "Print a table of lints to STDOUT. \
120 This does not include deprecated and internal lints. \
121 (Does not modify any files)",
124 Arg::with_name("check")
126 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
130 SubCommand::with_name("new_lint")
131 .about("Create new lint and run `cargo dev update_lints`")
133 Arg::with_name("pass")
136 .help("Specify whether the lint runs during the early or late pass")
138 .possible_values(&["early", "late"])
142 Arg::with_name("name")
145 .help("Name of the new lint in snake case, ex: fn_too_long")
150 Arg::with_name("category")
153 .help("What category the lint belongs to")
154 .default_value("nursery")
171 SubCommand::with_name("limit_stderr_length")
172 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
175 SubCommand::with_name("ra_setup")
176 .about("Alter dependencies so rust-analyzer can find rustc internals")
178 Arg::with_name("rustc-repo-path")
181 .help("The path to a rustc repo that will be used for setting the dependencies")
188 SubCommand::with_name("serve")
189 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
191 Arg::with_name("port")
194 .help("Local port for the http server")
195 .default_value("8000")
196 .validator_os(serve::validate_port),
198 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
201 #[cfg(feature = "lintcheck")]
202 let app = app.subcommand(lintcheck_sbcmd);