]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Merge remote-tracking branch 'upstream/master' into rustup
[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, ide_setup, new_lint, serve, stderr_length_check, update_lints};
5 fn main() {
6     let matches = get_clap_config();
7
8     match matches.subcommand() {
9         ("bless", Some(matches)) => {
10             bless::bless(matches.is_present("ignore-timestamp"));
11         },
12         ("fmt", Some(matches)) => {
13             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
14         },
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);
20             } else {
21                 update_lints::run(update_lints::UpdateMode::Change);
22             }
23         },
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"),
29             ) {
30                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
31                 Err(e) => eprintln!("Unable to create lint: {}", e),
32             }
33         },
34         ("limit_stderr_length", _) => {
35             stderr_length_check::check();
36         },
37         ("ide_setup", Some(matches)) => ide_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);
42         },
43         _ => {},
44     }
45 }
46
47 fn get_clap_config<'a>() -> ArgMatches<'a> {
48     App::new("Clippy developer tooling")
49         .subcommand(
50             SubCommand::with_name("bless")
51                 .about("bless the test output changes")
52                 .arg(
53                     Arg::with_name("ignore-timestamp")
54                         .long("ignore-timestamp")
55                         .help("Include files updated before clippy was built"),
56                 ),
57         )
58         .subcommand(
59             SubCommand::with_name("fmt")
60                 .about("Run rustfmt on all projects and tests")
61                 .arg(
62                     Arg::with_name("check")
63                         .long("check")
64                         .help("Use the rustfmt --check option"),
65                 )
66                 .arg(
67                     Arg::with_name("verbose")
68                         .short("v")
69                         .long("verbose")
70                         .help("Echo commands run"),
71                 ),
72         )
73         .subcommand(
74             SubCommand::with_name("update_lints")
75                 .about("Updates lint registration and information from the source code")
76                 .long_about(
77                     "Makes sure that:\n \
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",
83                 )
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)",
88                 ))
89                 .arg(
90                     Arg::with_name("check")
91                         .long("check")
92                         .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
93                 ),
94         )
95         .subcommand(
96             SubCommand::with_name("new_lint")
97                 .about("Create new lint and run `cargo dev update_lints`")
98                 .arg(
99                     Arg::with_name("pass")
100                         .short("p")
101                         .long("pass")
102                         .help("Specify whether the lint runs during the early or late pass")
103                         .takes_value(true)
104                         .possible_values(&["early", "late"])
105                         .required(true),
106                 )
107                 .arg(
108                     Arg::with_name("name")
109                         .short("n")
110                         .long("name")
111                         .help("Name of the new lint in snake case, ex: fn_too_long")
112                         .takes_value(true)
113                         .required(true),
114                 )
115                 .arg(
116                     Arg::with_name("category")
117                         .short("c")
118                         .long("category")
119                         .help("What category the lint belongs to")
120                         .default_value("nursery")
121                         .possible_values(&[
122                             "style",
123                             "correctness",
124                             "complexity",
125                             "perf",
126                             "pedantic",
127                             "restriction",
128                             "cargo",
129                             "nursery",
130                             "internal",
131                             "internal_warn",
132                         ])
133                         .takes_value(true),
134                 ),
135         )
136         .subcommand(
137             SubCommand::with_name("limit_stderr_length")
138                 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
139         )
140         .subcommand(
141             SubCommand::with_name("ide_setup")
142                 .about("Alter dependencies so Intellij Rust can find rustc internals")
143                 .arg(
144                     Arg::with_name("rustc-repo-path")
145                         .long("repo-path")
146                         .short("r")
147                         .help("The path to a rustc repo that will be used for setting the dependencies")
148                         .takes_value(true)
149                         .value_name("path")
150                         .required(true),
151                 ),
152         )
153         .subcommand(
154             SubCommand::with_name("serve")
155                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
156                 .arg(
157                     Arg::with_name("port")
158                         .long("port")
159                         .short("p")
160                         .help("Local port for the http server")
161                         .default_value("8000")
162                         .validator_os(serve::validate_port),
163                 )
164                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
165         )
166         .get_matches()
167 }