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