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