]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Auto merge of #6450 - matthiaskrgr:dont_format_local_repo, r=ebroto
[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(_)) => {
11             bless::bless();
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(SubCommand::with_name("bless").about("bless the test output changes"))
51         .subcommand(
52             SubCommand::with_name("fmt")
53                 .about("Run rustfmt on all projects and tests")
54                 .arg(
55                     Arg::with_name("check")
56                         .long("check")
57                         .help("Use the rustfmt --check option"),
58                 )
59                 .arg(
60                     Arg::with_name("verbose")
61                         .short("v")
62                         .long("verbose")
63                         .help("Echo commands run"),
64                 ),
65         )
66         .subcommand(
67             SubCommand::with_name("update_lints")
68                 .about("Updates lint registration and information from the source code")
69                 .long_about(
70                     "Makes sure that:\n \
71                  * the lint count in README.md is correct\n \
72                  * the changelog contains markdown link references at the bottom\n \
73                  * all lint groups include the correct lints\n \
74                  * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
75                  * all lints are registered in the lint store",
76                 )
77                 .arg(Arg::with_name("print-only").long("print-only").help(
78                     "Print a table of lints to STDOUT. \
79                  This does not include deprecated and internal lints. \
80                  (Does not modify any files)",
81                 ))
82                 .arg(
83                     Arg::with_name("check")
84                         .long("check")
85                         .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
86                 ),
87         )
88         .subcommand(
89             SubCommand::with_name("new_lint")
90                 .about("Create new lint and run `cargo dev update_lints`")
91                 .arg(
92                     Arg::with_name("pass")
93                         .short("p")
94                         .long("pass")
95                         .help("Specify whether the lint runs during the early or late pass")
96                         .takes_value(true)
97                         .possible_values(&["early", "late"])
98                         .required(true),
99                 )
100                 .arg(
101                     Arg::with_name("name")
102                         .short("n")
103                         .long("name")
104                         .help("Name of the new lint in snake case, ex: fn_too_long")
105                         .takes_value(true)
106                         .required(true),
107                 )
108                 .arg(
109                     Arg::with_name("category")
110                         .short("c")
111                         .long("category")
112                         .help("What category the lint belongs to")
113                         .default_value("nursery")
114                         .possible_values(&[
115                             "style",
116                             "correctness",
117                             "complexity",
118                             "perf",
119                             "pedantic",
120                             "restriction",
121                             "cargo",
122                             "nursery",
123                             "internal",
124                             "internal_warn",
125                         ])
126                         .takes_value(true),
127                 ),
128         )
129         .subcommand(
130             SubCommand::with_name("limit_stderr_length")
131                 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
132         )
133         .subcommand(
134             SubCommand::with_name("ra_setup")
135                 .about("Alter dependencies so rust-analyzer can find rustc internals")
136                 .arg(
137                     Arg::with_name("rustc-repo-path")
138                         .long("repo-path")
139                         .short("r")
140                         .help("The path to a rustc repo that will be used for setting the dependencies")
141                         .takes_value(true)
142                         .value_name("path")
143                         .required(true),
144                 ),
145         )
146         .subcommand(
147             SubCommand::with_name("serve")
148                 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
149                 .arg(
150                     Arg::with_name("port")
151                         .long("port")
152                         .short("p")
153                         .help("Local port for the http server")
154                         .default_value("8000")
155                         .validator_os(serve::validate_port),
156                 )
157                 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
158         )
159         .get_matches()
160 }