]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Auto merge of #7782 - dswij:shadow-unrelated-block, r=flip1995
[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, AppSettings, Arg, ArgMatches, SubCommand};
6 use clippy_dev::{bless, fmt, new_lint, serve, setup, 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         ("setup", Some(sub_command)) => match sub_command.subcommand() {
37             ("intellij", Some(matches)) => setup::intellij::setup_rustc_src(
38                 matches
39                     .value_of("rustc-repo-path")
40                     .expect("this field is mandatory and therefore always valid"),
41             ),
42             ("git-hook", Some(matches)) => setup::git_hook::install_hook(matches.is_present("force-override")),
43             ("vscode-tasks", Some(matches)) => setup::vscode::install_tasks(matches.is_present("force-override")),
44             _ => {},
45         },
46         ("remove", Some(sub_command)) => match sub_command.subcommand() {
47             ("git-hook", Some(_)) => setup::git_hook::remove_hook(),
48             ("intellij", Some(_)) => setup::intellij::remove_rustc_src(),
49             ("vscode-tasks", Some(_)) => setup::vscode::remove_tasks(),
50             _ => {},
51         },
52         ("serve", Some(matches)) => {
53             let port = matches.value_of("port").unwrap().parse().unwrap();
54             let lint = matches.value_of("lint");
55             serve::run(port, lint);
56         },
57         _ => {},
58     }
59 }
60
61 fn get_clap_config<'a>() -> ArgMatches<'a> {
62     App::new("Clippy developer tooling")
63         .setting(AppSettings::ArgRequiredElseHelp)
64         .subcommand(
65             SubCommand::with_name("bless")
66                 .about("bless the test output changes")
67                 .arg(
68                     Arg::with_name("ignore-timestamp")
69                         .long("ignore-timestamp")
70                         .help("Include files updated before clippy was built"),
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                             "suspicious",
140                             "complexity",
141                             "perf",
142                             "pedantic",
143                             "restriction",
144                             "cargo",
145                             "nursery",
146                             "internal",
147                             "internal_warn",
148                         ])
149                         .takes_value(true),
150                 ),
151         )
152         .subcommand(
153             SubCommand::with_name("setup")
154                 .about("Support for setting up your personal development environment")
155                 .setting(AppSettings::ArgRequiredElseHelp)
156                 .subcommand(
157                     SubCommand::with_name("intellij")
158                         .about("Alter dependencies so Intellij Rust can find rustc internals")
159                         .arg(
160                             Arg::with_name("rustc-repo-path")
161                                 .long("repo-path")
162                                 .short("r")
163                                 .help("The path to a rustc repo that will be used for setting the dependencies")
164                                 .takes_value(true)
165                                 .value_name("path")
166                                 .required(true),
167                         ),
168                 )
169                 .subcommand(
170                     SubCommand::with_name("git-hook")
171                         .about("Add a pre-commit git hook that formats your code to make it look pretty")
172                         .arg(
173                             Arg::with_name("force-override")
174                                 .long("force-override")
175                                 .short("f")
176                                 .help("Forces the override of an existing git pre-commit hook")
177                                 .required(false),
178                         ),
179                 )
180                 .subcommand(
181                     SubCommand::with_name("vscode-tasks")
182                         .about("Add several tasks to vscode for formatting, validation and testing")
183                         .arg(
184                             Arg::with_name("force-override")
185                                 .long("force-override")
186                                 .short("f")
187                                 .help("Forces the override of existing vscode tasks")
188                                 .required(false),
189                         ),
190                 ),
191         )
192         .subcommand(
193             SubCommand::with_name("remove")
194                 .about("Support for undoing changes done by the setup command")
195                 .setting(AppSettings::ArgRequiredElseHelp)
196                 .subcommand(SubCommand::with_name("git-hook").about("Remove any existing pre-commit git hook"))
197                 .subcommand(SubCommand::with_name("vscode-tasks").about("Remove any existing vscode tasks"))
198                 .subcommand(
199                     SubCommand::with_name("intellij")
200                         .about("Removes rustc source paths added via `cargo dev setup intellij`"),
201                 ),
202         )
203         .subcommand(
204             SubCommand::with_name("serve")
205                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
206                 .arg(
207                     Arg::with_name("port")
208                         .long("port")
209                         .short("p")
210                         .help("Local port for the http server")
211                         .default_value("8000")
212                         .validator_os(serve::validate_port),
213                 )
214                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
215         )
216         .get_matches()
217 }