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, AppSettings, Arg, ArgMatches, SubCommand};
6 use clippy_dev::{bless, fmt, new_lint, serve, setup, 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 ("setup", Some(sub_command)) => match sub_command.subcommand() {
40 ("intellij", Some(matches)) => setup::intellij::setup_rustc_src(
42 .value_of("rustc-repo-path")
43 .expect("this field is mandatory and therefore always valid"),
45 ("git-hook", Some(matches)) => setup::git_hook::install_hook(matches.is_present("force-override")),
48 ("remove", Some(sub_command)) => {
49 if let ("git-hook", Some(_)) = sub_command.subcommand() {
50 setup::git_hook::remove_hook();
53 ("serve", Some(matches)) => {
54 let port = matches.value_of("port").unwrap().parse().unwrap();
55 let lint = matches.value_of("lint");
56 serve::run(port, lint);
62 fn get_clap_config<'a>() -> ArgMatches<'a> {
63 App::new("Clippy developer tooling")
64 .setting(AppSettings::ArgRequiredElseHelp)
66 SubCommand::with_name("bless")
67 .about("bless the test output changes")
69 Arg::with_name("ignore-timestamp")
70 .long("ignore-timestamp")
71 .help("Include files updated before clippy was built"),
75 SubCommand::with_name("fmt")
76 .about("Run rustfmt on all projects and tests")
78 Arg::with_name("check")
80 .help("Use the rustfmt --check option"),
83 Arg::with_name("verbose")
86 .help("Echo commands run"),
90 SubCommand::with_name("update_lints")
91 .about("Updates lint registration and information from the source code")
94 * the lint count in README.md is correct\n \
95 * the changelog contains markdown link references at the bottom\n \
96 * all lint groups include the correct lints\n \
97 * lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
98 * all lints are registered in the lint store",
100 .arg(Arg::with_name("print-only").long("print-only").help(
101 "Print a table of lints to STDOUT. \
102 This does not include deprecated and internal lints. \
103 (Does not modify any files)",
106 Arg::with_name("check")
108 .help("Checks that `cargo dev update_lints` has been run. Used on CI."),
112 SubCommand::with_name("new_lint")
113 .about("Create new lint and run `cargo dev update_lints`")
115 Arg::with_name("pass")
118 .help("Specify whether the lint runs during the early or late pass")
120 .possible_values(&["early", "late"])
124 Arg::with_name("name")
127 .help("Name of the new lint in snake case, ex: fn_too_long")
132 Arg::with_name("category")
135 .help("What category the lint belongs to")
136 .default_value("nursery")
153 SubCommand::with_name("limit_stderr_length")
154 .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
157 SubCommand::with_name("setup")
158 .about("Support for setting up your personal development environment")
159 .setting(AppSettings::ArgRequiredElseHelp)
161 SubCommand::with_name("intellij")
162 .about("Alter dependencies so Intellij Rust can find rustc internals")
164 Arg::with_name("rustc-repo-path")
167 .help("The path to a rustc repo that will be used for setting the dependencies")
174 SubCommand::with_name("git-hook")
175 .about("Add a pre-commit git hook that formats your code to make it look pretty")
177 Arg::with_name("force-override")
178 .long("force-override")
180 .help("Forces the override of an existing git pre-commit hook")
186 SubCommand::with_name("remove")
187 .about("Support for undoing changes done by the setup command")
188 .setting(AppSettings::ArgRequiredElseHelp)
189 .subcommand(SubCommand::with_name("git-hook").about("Remove any existing pre-commit git hook")),
192 SubCommand::with_name("serve")
193 .about("Launch a local 'ALL the Clippy Lints' website in a browser")
195 Arg::with_name("port")
198 .help("Local port for the http server")
199 .default_value("8000")
200 .validator_os(serve::validate_port),
202 .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),