1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
2 // warn on lints, that are included in `rust-lang/rust`s bootstrap
3 #![warn(rust_2018_idioms, unused_lifetimes)]
5 use clap::{App, Arg, ArgMatches, SubCommand};
6 use clippy_dev::{bless, fmt, ide_setup, new_lint, serve, stderr_length_check, update_lints};
8 let matches = get_clap_config();
10 match matches.subcommand() {
11 ("bless", Some(matches)) => {
12 bless::bless(matches.is_present("ignore-timestamp"));
14 ("fmt", Some(matches)) => {
15 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
17 ("update_lints", Some(matches)) => {
18 if matches.is_present("print-only") {
19 update_lints::print_lints();
20 } else if matches.is_present("check") {
21 update_lints::run(update_lints::UpdateMode::Check);
23 update_lints::run(update_lints::UpdateMode::Change);
26 ("new_lint", Some(matches)) => {
27 match new_lint::create(
28 matches.value_of("pass"),
29 matches.value_of("name"),
30 matches.value_of("category"),
32 Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
33 Err(e) => eprintln!("Unable to create lint: {}", e),
36 ("limit_stderr_length", _) => {
37 stderr_length_check::check();
39 ("ide_setup", Some(matches)) => ide_setup::run(matches.value_of("rustc-repo-path")),
40 ("serve", Some(matches)) => {
41 let port = matches.value_of("port").unwrap().parse().unwrap();
42 let lint = matches.value_of("lint");
43 serve::run(port, lint);
49 fn get_clap_config<'a>() -> ArgMatches<'a> {
50 App::new("Clippy developer tooling")
52 SubCommand::with_name("bless")
53 .about("bless the test output changes")
55 Arg::with_name("ignore-timestamp")
56 .long("ignore-timestamp")
57 .help("Include files updated before clippy was built"),
61 SubCommand::with_name("fmt")
62 .about("Run rustfmt on all projects and tests")
64 Arg::with_name("check")
66 .help("Use the rustfmt --check option"),
69 Arg::with_name("verbose")
72 .help("Echo commands run"),
76 SubCommand::with_name("update_lints")
77 .about("Updates lint registration and information from the source code")
80 * the lint count in README.md is correct\n \
81 * the changelog contains markdown link references at the bottom\n \
82 * all lint groups include the correct lints\n \
83 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
84 * all lints are registered in the lint store",
86 .arg(Arg::with_name("print-only").long("print-only").help(
87 "Print a table of lints to STDOUT. \
88 This does not include deprecated and internal lints. \
89 (Does not modify any files)",
92 Arg::with_name("check")
94 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
98 SubCommand::with_name("new_lint")
99 .about("Create new lint and run `cargo dev update_lints`")
101 Arg::with_name("pass")
104 .help("Specify whether the lint runs during the early or late pass")
106 .possible_values(&["early", "late"])
110 Arg::with_name("name")
113 .help("Name of the new lint in snake case, ex: fn_too_long")
118 Arg::with_name("category")
121 .help("What category the lint belongs to")
122 .default_value("nursery")
139 SubCommand::with_name("limit_stderr_length")
140 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
143 SubCommand::with_name("ide_setup")
144 .about("Alter dependencies so Intellij Rust can find rustc internals")
146 Arg::with_name("rustc-repo-path")
149 .help("The path to a rustc repo that will be used for setting the dependencies")
156 SubCommand::with_name("serve")
157 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
159 Arg::with_name("port")
162 .help("Local port for the http server")
163 .default_value("8000")
164 .validator_os(serve::validate_port),
166 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),