]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/main.rs
Merge remote-tracking branch 'upstream/master' into clippy-fix
[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, 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         .get_matches();
91
92     match matches.subcommand() {
93         ("fmt", Some(matches)) => {
94             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
95         },
96         ("update_lints", Some(matches)) => {
97             if matches.is_present("print-only") {
98                 update_lints::print_lints();
99             } else if matches.is_present("check") {
100                 update_lints::run(update_lints::UpdateMode::Check);
101             } else {
102                 update_lints::run(update_lints::UpdateMode::Change);
103             }
104         },
105         ("new_lint", Some(matches)) => {
106             match new_lint::create(
107                 matches.value_of("pass"),
108                 matches.value_of("name"),
109                 matches.value_of("category"),
110             ) {
111                 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
112                 Err(e) => eprintln!("Unable to create lint: {}", e),
113             }
114         },
115         ("limit_stderr_length", _) => {
116             stderr_length_check::check();
117         },
118         _ => {},
119     }
120 }