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