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