]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Merge commit 'ff0993c5e9162ddaea78e83d0f0161e68bd4ea73' into clippy
[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, 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         .get_matches();
104
105     match matches.subcommand() {
106         ("fmt", Some(matches)) => {
107             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
108         },
109         ("update_lints", Some(matches)) => {
110             if matches.is_present("print-only") {
111                 update_lints::print_lints();
112             } else if matches.is_present("check") {
113                 update_lints::run(update_lints::UpdateMode::Check);
114             } else {
115                 update_lints::run(update_lints::UpdateMode::Change);
116             }
117         },
118         ("new_lint", Some(matches)) => {
119             match new_lint::create(
120                 matches.value_of("pass"),
121                 matches.value_of("name"),
122                 matches.value_of("category"),
123             ) {
124                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
125                 Err(e) => eprintln!("Unable to create lint: {}", e),
126             }
127         },
128         ("limit_stderr_length", _) => {
129             stderr_length_check::check();
130         },
131         ("ra-setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
132         _ => {},
133     }
134 }