]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_dev/src/main.rs
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
[rust.git] / src / tools / clippy / 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                 matches.is_present("msrv"),
32             ) {
33                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
34                 Err(e) => eprintln!("Unable to create lint: {}", e),
35             }
36         },
37         ("setup", Some(sub_command)) => match sub_command.subcommand() {
38             ("intellij", Some(matches)) => setup::intellij::setup_rustc_src(
39                 matches
40                     .value_of("rustc-repo-path")
41                     .expect("this field is mandatory and therefore always valid"),
42             ),
43             ("git-hook", Some(matches)) => setup::git_hook::install_hook(matches.is_present("force-override")),
44             ("vscode-tasks", Some(matches)) => setup::vscode::install_tasks(matches.is_present("force-override")),
45             _ => {},
46         },
47         ("remove", Some(sub_command)) => match sub_command.subcommand() {
48             ("git-hook", Some(_)) => setup::git_hook::remove_hook(),
49             ("intellij", Some(_)) => setup::intellij::remove_rustc_src(),
50             ("vscode-tasks", Some(_)) => setup::vscode::remove_tasks(),
51             _ => {},
52         },
53         ("serve", Some(matches)) => {
54             let port = matches.value_of("port").unwrap().parse().unwrap();
55             let lint = matches.value_of("lint");
56             serve::run(port, lint);
57         },
58         _ => {},
59     }
60 }
61
62 fn get_clap_config<'a>() -> ArgMatches<'a> {
63     App::new("Clippy developer tooling")
64         .setting(AppSettings::ArgRequiredElseHelp)
65         .subcommand(
66             SubCommand::with_name("bless")
67                 .about("bless the test output changes")
68                 .arg(
69                     Arg::with_name("ignore-timestamp")
70                         .long("ignore-timestamp")
71                         .help("Include files updated before clippy was built"),
72                 ),
73         )
74         .subcommand(
75             SubCommand::with_name("fmt")
76                 .about("Run rustfmt on all projects and tests")
77                 .arg(
78                     Arg::with_name("check")
79                         .long("check")
80                         .help("Use the rustfmt --check option"),
81                 )
82                 .arg(
83                     Arg::with_name("verbose")
84                         .short("v")
85                         .long("verbose")
86                         .help("Echo commands run"),
87                 ),
88         )
89         .subcommand(
90             SubCommand::with_name("update_lints")
91                 .about("Updates lint registration and information from the source code")
92                 .long_about(
93                     "Makes sure that:\n \
94                  * the lint count in README.md is correct\n \
95                  * the changelog contains markdown link references at the bottom\n \
96                  * all lint groups include the correct lints\n \
97                  * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
98                  * all lints are registered in the lint store",
99                 )
100                 .arg(Arg::with_name("print-only").long("print-only").help(
101                     "Print a table of lints to STDOUT. \
102                  This does not include deprecated and internal lints. \
103                  (Does not modify any files)",
104                 ))
105                 .arg(
106                     Arg::with_name("check")
107                         .long("check")
108                         .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
109                 ),
110         )
111         .subcommand(
112             SubCommand::with_name("new_lint")
113                 .about("Create new lint and run `cargo dev update_lints`")
114                 .arg(
115                     Arg::with_name("pass")
116                         .short("p")
117                         .long("pass")
118                         .help("Specify whether the lint runs during the early or late pass")
119                         .takes_value(true)
120                         .possible_values(&["early", "late"])
121                         .required(true),
122                 )
123                 .arg(
124                     Arg::with_name("name")
125                         .short("n")
126                         .long("name")
127                         .help("Name of the new lint in snake case, ex: fn_too_long")
128                         .takes_value(true)
129                         .required(true),
130                 )
131                 .arg(
132                     Arg::with_name("category")
133                         .short("c")
134                         .long("category")
135                         .help("What category the lint belongs to")
136                         .default_value("nursery")
137                         .possible_values(&[
138                             "style",
139                             "correctness",
140                             "suspicious",
141                             "complexity",
142                             "perf",
143                             "pedantic",
144                             "restriction",
145                             "cargo",
146                             "nursery",
147                             "internal",
148                             "internal_warn",
149                         ])
150                         .takes_value(true),
151                 )
152                 .arg(
153                     Arg::with_name("msrv")
154                         .long("msrv")
155                         .help("Add MSRV config code to the lint"),
156                 ),
157         )
158         .subcommand(
159             SubCommand::with_name("setup")
160                 .about("Support for setting up your personal development environment")
161                 .setting(AppSettings::ArgRequiredElseHelp)
162                 .subcommand(
163                     SubCommand::with_name("intellij")
164                         .about("Alter dependencies so Intellij Rust can find rustc internals")
165                         .arg(
166                             Arg::with_name("rustc-repo-path")
167                                 .long("repo-path")
168                                 .short("r")
169                                 .help("The path to a rustc repo that will be used for setting the dependencies")
170                                 .takes_value(true)
171                                 .value_name("path")
172                                 .required(true),
173                         ),
174                 )
175                 .subcommand(
176                     SubCommand::with_name("git-hook")
177                         .about("Add a pre-commit git hook that formats your code to make it look pretty")
178                         .arg(
179                             Arg::with_name("force-override")
180                                 .long("force-override")
181                                 .short("f")
182                                 .help("Forces the override of an existing git pre-commit hook")
183                                 .required(false),
184                         ),
185                 )
186                 .subcommand(
187                     SubCommand::with_name("vscode-tasks")
188                         .about("Add several tasks to vscode for formatting, validation and testing")
189                         .arg(
190                             Arg::with_name("force-override")
191                                 .long("force-override")
192                                 .short("f")
193                                 .help("Forces the override of existing vscode tasks")
194                                 .required(false),
195                         ),
196                 ),
197         )
198         .subcommand(
199             SubCommand::with_name("remove")
200                 .about("Support for undoing changes done by the setup command")
201                 .setting(AppSettings::ArgRequiredElseHelp)
202                 .subcommand(SubCommand::with_name("git-hook").about("Remove any existing pre-commit git hook"))
203                 .subcommand(SubCommand::with_name("vscode-tasks").about("Remove any existing vscode tasks"))
204                 .subcommand(
205                     SubCommand::with_name("intellij")
206                         .about("Removes rustc source paths added via `cargo dev setup intellij`"),
207                 ),
208         )
209         .subcommand(
210             SubCommand::with_name("serve")
211                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
212                 .arg(
213                     Arg::with_name("port")
214                         .long("port")
215                         .short("p")
216                         .help("Local port for the http server")
217                         .default_value("8000")
218                         .validator_os(serve::validate_port),
219                 )
220                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
221         )
222         .get_matches()
223 }