]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
clippy dev crater: add option to only check a single one of the listed crates with...
[rust.git] / clippy_dev / src / main.rs
1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
2
3 use clap::{App, Arg, ArgMatches, SubCommand};
4 use clippy_dev::{bless, crater, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
5
6 fn main() {
7     let matches = get_clap_config();
8
9     match matches.subcommand() {
10         ("bless", Some(matches)) => {
11             bless::bless(matches.is_present("ignore-timestamp"));
12         },
13         ("crater", Some(matches)) => {
14             crater::run(&matches);
15         },
16         ("fmt", Some(matches)) => {
17             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
18         },
19         ("update_lints", Some(matches)) => {
20             if matches.is_present("print-only") {
21                 update_lints::print_lints();
22             } else if matches.is_present("check") {
23                 update_lints::run(update_lints::UpdateMode::Check);
24             } else {
25                 update_lints::run(update_lints::UpdateMode::Change);
26             }
27         },
28         ("new_lint", Some(matches)) => {
29             match new_lint::create(
30                 matches.value_of("pass"),
31                 matches.value_of("name"),
32                 matches.value_of("category"),
33             ) {
34                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
35                 Err(e) => eprintln!("Unable to create lint: {}", e),
36             }
37         },
38         ("limit_stderr_length", _) => {
39             stderr_length_check::check();
40         },
41         ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
42         ("serve", Some(matches)) => {
43             let port = matches.value_of("port").unwrap().parse().unwrap();
44             let lint = matches.value_of("lint");
45             serve::run(port, lint);
46         },
47         _ => {},
48     }
49 }
50
51 fn get_clap_config<'a>() -> ArgMatches<'a> {
52     App::new("Clippy developer tooling")
53         .subcommand(
54             SubCommand::with_name("bless")
55                 .about("bless the test output changes")
56                 .arg(
57                     Arg::with_name("ignore-timestamp")
58                         .long("ignore-timestamp")
59                         .help("Include files updated before clippy was built"),
60                 ),
61         )
62         .subcommand(
63             SubCommand::with_name("crater")
64                 .about("run clippy on a set of crates and check output")
65                 .arg(
66                     Arg::with_name("only")
67                         .takes_value(true)
68                         .value_name("CRATE")
69                         .long("only")
70                         .help("only process a single crate of the list"),
71                 ),
72         )
73         .subcommand(
74             SubCommand::with_name("fmt")
75                 .about("Run rustfmt on all projects and tests")
76                 .arg(
77                     Arg::with_name("check")
78                         .long("check")
79                         .help("Use the rustfmt --check option"),
80                 )
81                 .arg(
82                     Arg::with_name("verbose")
83                         .short("v")
84                         .long("verbose")
85                         .help("Echo commands run"),
86                 ),
87         )
88         .subcommand(
89             SubCommand::with_name("update_lints")
90                 .about("Updates lint registration and information from the source code")
91                 .long_about(
92                     "Makes sure that:\n \
93                  * the lint count in README.md is correct\n \
94                  * the changelog contains markdown link references at the bottom\n \
95                  * all lint groups include the correct lints\n \
96                  * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
97                  * all lints are registered in the lint store",
98                 )
99                 .arg(Arg::with_name("print-only").long("print-only").help(
100                     "Print a table of lints to STDOUT. \
101                  This does not include deprecated and internal lints. \
102                  (Does not modify any files)",
103                 ))
104                 .arg(
105                     Arg::with_name("check")
106                         .long("check")
107                         .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
108                 ),
109         )
110         .subcommand(
111             SubCommand::with_name("new_lint")
112                 .about("Create new lint and run `cargo dev update_lints`")
113                 .arg(
114                     Arg::with_name("pass")
115                         .short("p")
116                         .long("pass")
117                         .help("Specify whether the lint runs during the early or late pass")
118                         .takes_value(true)
119                         .possible_values(&["early", "late"])
120                         .required(true),
121                 )
122                 .arg(
123                     Arg::with_name("name")
124                         .short("n")
125                         .long("name")
126                         .help("Name of the new lint in snake case, ex: fn_too_long")
127                         .takes_value(true)
128                         .required(true),
129                 )
130                 .arg(
131                     Arg::with_name("category")
132                         .short("c")
133                         .long("category")
134                         .help("What category the lint belongs to")
135                         .default_value("nursery")
136                         .possible_values(&[
137                             "style",
138                             "correctness",
139                             "complexity",
140                             "perf",
141                             "pedantic",
142                             "restriction",
143                             "cargo",
144                             "nursery",
145                             "internal",
146                             "internal_warn",
147                         ])
148                         .takes_value(true),
149                 ),
150         )
151         .subcommand(
152             SubCommand::with_name("limit_stderr_length")
153                 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
154         )
155         .subcommand(
156             SubCommand::with_name("ra_setup")
157                 .about("Alter dependencies so rust-analyzer can find rustc internals")
158                 .arg(
159                     Arg::with_name("rustc-repo-path")
160                         .long("repo-path")
161                         .short("r")
162                         .help("The path to a rustc repo that will be used for setting the dependencies")
163                         .takes_value(true)
164                         .value_name("path")
165                         .required(true),
166                 ),
167         )
168         .subcommand(
169             SubCommand::with_name("serve")
170                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
171                 .arg(
172                     Arg::with_name("port")
173                         .long("port")
174                         .short("p")
175                         .help("Local port for the http server")
176                         .default_value("8000")
177                         .validator_os(serve::validate_port),
178                 )
179                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
180         )
181         .get_matches()
182 }