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