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