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