2019-11-25 10:23:48 -06:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
2021-05-20 05:30:31 -05:00
|
|
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2019-11-25 10:23:48 -06:00
|
|
|
|
2022-06-16 10:39:06 -05:00
|
|
|
use clap::{Arg, ArgAction, ArgMatches, Command, PossibleValue};
|
2022-07-18 02:39:37 -05:00
|
|
|
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
|
2022-04-07 12:39:59 -05:00
|
|
|
use indoc::indoc;
|
2022-06-30 03:50:09 -05:00
|
|
|
|
2018-07-17 15:50:17 -05:00
|
|
|
fn main() {
|
2020-12-20 10:19:49 -06:00
|
|
|
let matches = get_clap_config();
|
|
|
|
|
|
|
|
match matches.subcommand() {
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("bless", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
bless::bless(matches.contains_id("ignore-timestamp"));
|
2020-12-20 10:19:49 -06:00
|
|
|
},
|
2022-07-18 02:39:37 -05:00
|
|
|
Some(("dogfood", matches)) => {
|
|
|
|
dogfood::dogfood(
|
|
|
|
matches.contains_id("fix"),
|
|
|
|
matches.contains_id("allow-dirty"),
|
|
|
|
matches.contains_id("allow-staged"),
|
|
|
|
);
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("fmt", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
fmt::run(matches.contains_id("check"), matches.contains_id("verbose"));
|
2020-12-20 10:19:49 -06:00
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("update_lints", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
if matches.contains_id("print-only") {
|
2020-12-20 10:19:49 -06:00
|
|
|
update_lints::print_lints();
|
2022-06-16 10:39:06 -05:00
|
|
|
} else if matches.contains_id("check") {
|
2022-05-05 09:12:52 -05:00
|
|
|
update_lints::update(update_lints::UpdateMode::Check);
|
2020-12-20 10:19:49 -06:00
|
|
|
} else {
|
2022-05-05 09:12:52 -05:00
|
|
|
update_lints::update(update_lints::UpdateMode::Change);
|
2020-12-20 10:19:49 -06:00
|
|
|
}
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("new_lint", matches)) => {
|
2020-12-20 10:19:49 -06:00
|
|
|
match new_lint::create(
|
2022-06-16 10:39:06 -05:00
|
|
|
matches.get_one::<String>("pass"),
|
|
|
|
matches.get_one::<String>("name"),
|
2022-07-28 12:08:22 -05:00
|
|
|
matches.get_one::<String>("category").map(String::as_str),
|
|
|
|
matches.get_one::<String>("type").map(String::as_str),
|
2022-06-16 10:39:06 -05:00
|
|
|
matches.contains_id("msrv"),
|
2020-12-20 10:19:49 -06:00
|
|
|
) {
|
2022-05-05 09:12:52 -05:00
|
|
|
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
|
2020-12-20 10:19:49 -06:00
|
|
|
Err(e) => eprintln!("Unable to create lint: {}", e),
|
|
|
|
}
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("setup", sub_command)) => match sub_command.subcommand() {
|
|
|
|
Some(("intellij", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
if matches.contains_id("remove") {
|
2022-05-05 09:12:52 -05:00
|
|
|
setup::intellij::remove_rustc_src();
|
|
|
|
} else {
|
|
|
|
setup::intellij::setup_rustc_src(
|
|
|
|
matches
|
2022-06-16 10:39:06 -05:00
|
|
|
.get_one::<String>("rustc-repo-path")
|
2022-05-05 09:12:52 -05:00
|
|
|
.expect("this field is mandatory and therefore always valid"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("git-hook", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
if matches.contains_id("remove") {
|
2022-05-05 09:12:52 -05:00
|
|
|
setup::git_hook::remove_hook();
|
|
|
|
} else {
|
2022-06-16 10:39:06 -05:00
|
|
|
setup::git_hook::install_hook(matches.contains_id("force-override"));
|
2022-05-05 09:12:52 -05:00
|
|
|
}
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("vscode-tasks", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
if matches.contains_id("remove") {
|
2022-05-05 09:12:52 -05:00
|
|
|
setup::vscode::remove_tasks();
|
|
|
|
} else {
|
2022-06-16 10:39:06 -05:00
|
|
|
setup::vscode::install_tasks(matches.contains_id("force-override"));
|
2022-05-05 09:12:52 -05:00
|
|
|
}
|
|
|
|
},
|
2021-07-01 11:17:38 -05:00
|
|
|
_ => {},
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("remove", sub_command)) => match sub_command.subcommand() {
|
|
|
|
Some(("git-hook", _)) => setup::git_hook::remove_hook(),
|
|
|
|
Some(("intellij", _)) => setup::intellij::remove_rustc_src(),
|
|
|
|
Some(("vscode-tasks", _)) => setup::vscode::remove_tasks(),
|
2021-07-01 11:17:38 -05:00
|
|
|
_ => {},
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("serve", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
let port = *matches.get_one::<u16>("port").unwrap();
|
|
|
|
let lint = matches.get_one::<String>("lint");
|
2020-12-20 10:19:49 -06:00
|
|
|
serve::run(port, lint);
|
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("lint", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
let path = matches.get_one::<String>("path").unwrap();
|
|
|
|
let args = matches.get_many::<String>("args").into_iter().flatten();
|
2022-05-21 06:24:00 -05:00
|
|
|
lint::run(path, args);
|
2021-12-06 05:33:31 -06:00
|
|
|
},
|
2022-06-04 06:34:07 -05:00
|
|
|
Some(("rename_lint", matches)) => {
|
2022-06-16 10:39:06 -05:00
|
|
|
let old_name = matches.get_one::<String>("old_name").unwrap();
|
|
|
|
let new_name = matches.get_one::<String>("new_name").unwrap_or(old_name);
|
|
|
|
let uplift = matches.contains_id("uplift");
|
2022-05-05 09:12:52 -05:00
|
|
|
update_lints::rename(old_name, new_name, uplift);
|
|
|
|
},
|
2022-06-30 03:50:09 -05:00
|
|
|
Some(("deprecate", matches)) => {
|
|
|
|
let name = matches.get_one::<String>("name").unwrap();
|
|
|
|
let reason = matches.get_one("reason");
|
|
|
|
update_lints::deprecate(name, reason);
|
|
|
|
},
|
2020-12-20 10:19:49 -06:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-04 06:34:07 -05:00
|
|
|
fn get_clap_config() -> ArgMatches {
|
|
|
|
Command::new("Clippy developer tooling")
|
|
|
|
.arg_required_else_help(true)
|
2022-06-16 10:39:06 -05:00
|
|
|
.subcommands([
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("bless").about("bless the test output changes").arg(
|
|
|
|
Arg::new("ignore-timestamp")
|
|
|
|
.long("ignore-timestamp")
|
|
|
|
.help("Include files updated before clippy was built"),
|
|
|
|
),
|
2022-07-18 02:39:37 -05:00
|
|
|
Command::new("dogfood").about("Runs the dogfood test").args([
|
|
|
|
Arg::new("fix").long("fix").help("Apply the suggestions when possible"),
|
|
|
|
Arg::new("allow-dirty")
|
|
|
|
.long("allow-dirty")
|
|
|
|
.help("Fix code even if the working directory has changes")
|
|
|
|
.requires("fix"),
|
|
|
|
Arg::new("allow-staged")
|
|
|
|
.long("allow-staged")
|
|
|
|
.help("Fix code even if the working directory has staged changes")
|
|
|
|
.requires("fix"),
|
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("fmt")
|
2019-06-24 23:43:38 -05:00
|
|
|
.about("Run rustfmt on all projects and tests")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
|
|
|
Arg::new("check").long("check").help("Use the rustfmt --check option"),
|
|
|
|
Arg::new("verbose").short('v').long("verbose").help("Echo commands run"),
|
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("update_lints")
|
2019-03-07 23:45:31 -06:00
|
|
|
.about("Updates lint registration and information from the source code")
|
|
|
|
.long_about(
|
2018-11-27 14:13:08 -06:00
|
|
|
"Makes sure that:\n \
|
2022-06-16 10:39:06 -05:00
|
|
|
* the lint count in README.md is correct\n \
|
|
|
|
* the changelog contains markdown link references at the bottom\n \
|
|
|
|
* all lint groups include the correct lints\n \
|
|
|
|
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
|
|
|
|
* all lints are registered in the lint store",
|
2018-11-04 02:41:28 -06:00
|
|
|
)
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
|
|
|
Arg::new("print-only").long("print-only").help(
|
|
|
|
"Print a table of lints to STDOUT. \
|
|
|
|
This does not include deprecated and internal lints. \
|
|
|
|
(Does not modify any files)",
|
|
|
|
),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("check")
|
2018-11-04 02:41:28 -06:00
|
|
|
.long("check")
|
2020-01-30 01:33:48 -06:00
|
|
|
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("new_lint")
|
2020-01-30 01:33:48 -06:00
|
|
|
.about("Create new lint and run `cargo dev update_lints`")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("pass")
|
|
|
|
.short('p')
|
2019-12-31 19:07:39 -06:00
|
|
|
.long("pass")
|
|
|
|
.help("Specify whether the lint runs during the early or late pass")
|
|
|
|
.takes_value(true)
|
2022-06-16 10:39:06 -05:00
|
|
|
.value_parser([PossibleValue::new("early"), PossibleValue::new("late")])
|
2022-07-28 12:08:22 -05:00
|
|
|
.conflicts_with("type")
|
|
|
|
.required_unless_present("type"),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("name")
|
|
|
|
.short('n')
|
2019-12-31 19:07:39 -06:00
|
|
|
.long("name")
|
|
|
|
.help("Name of the new lint in snake case, ex: fn_too_long")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("category")
|
|
|
|
.short('c')
|
2019-12-31 19:07:39 -06:00
|
|
|
.long("category")
|
|
|
|
.help("What category the lint belongs to")
|
|
|
|
.default_value("nursery")
|
2022-06-16 10:39:06 -05:00
|
|
|
.value_parser([
|
|
|
|
PossibleValue::new("style"),
|
|
|
|
PossibleValue::new("correctness"),
|
|
|
|
PossibleValue::new("suspicious"),
|
|
|
|
PossibleValue::new("complexity"),
|
|
|
|
PossibleValue::new("perf"),
|
|
|
|
PossibleValue::new("pedantic"),
|
|
|
|
PossibleValue::new("restriction"),
|
|
|
|
PossibleValue::new("cargo"),
|
|
|
|
PossibleValue::new("nursery"),
|
|
|
|
PossibleValue::new("internal"),
|
|
|
|
PossibleValue::new("internal_warn"),
|
2019-12-31 19:07:39 -06:00
|
|
|
])
|
|
|
|
.takes_value(true),
|
2022-07-28 12:08:22 -05:00
|
|
|
Arg::new("type")
|
|
|
|
.long("type")
|
|
|
|
.help("What directory the lint belongs in")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(false),
|
2022-06-16 10:39:06 -05:00
|
|
|
Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint"),
|
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("setup")
|
2021-07-01 11:17:38 -05:00
|
|
|
.about("Support for setting up your personal development environment")
|
2022-06-04 06:34:07 -05:00
|
|
|
.arg_required_else_help(true)
|
2022-06-16 10:39:06 -05:00
|
|
|
.subcommands([
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("intellij")
|
2021-07-01 11:17:38 -05:00
|
|
|
.about("Alter dependencies so Intellij Rust can find rustc internals")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("remove")
|
2022-05-05 09:12:52 -05:00
|
|
|
.long("remove")
|
|
|
|
.help("Remove the dependencies added with 'cargo dev setup intellij'")
|
|
|
|
.required(false),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("rustc-repo-path")
|
2021-07-01 11:17:38 -05:00
|
|
|
.long("repo-path")
|
2022-06-04 06:34:07 -05:00
|
|
|
.short('r')
|
2021-07-01 11:17:38 -05:00
|
|
|
.help("The path to a rustc repo that will be used for setting the dependencies")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("path")
|
2022-05-05 09:12:52 -05:00
|
|
|
.conflicts_with("remove")
|
2021-07-01 11:17:38 -05:00
|
|
|
.required(true),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("git-hook")
|
2021-07-01 11:17:38 -05:00
|
|
|
.about("Add a pre-commit git hook that formats your code to make it look pretty")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("remove")
|
2022-05-05 09:12:52 -05:00
|
|
|
.long("remove")
|
|
|
|
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'")
|
|
|
|
.required(false),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("force-override")
|
2021-07-01 11:17:38 -05:00
|
|
|
.long("force-override")
|
2022-06-04 06:34:07 -05:00
|
|
|
.short('f')
|
2021-07-01 11:17:38 -05:00
|
|
|
.help("Forces the override of an existing git pre-commit hook")
|
|
|
|
.required(false),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("vscode-tasks")
|
2021-07-01 11:17:38 -05:00
|
|
|
.about("Add several tasks to vscode for formatting, validation and testing")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("remove")
|
2022-05-05 09:12:52 -05:00
|
|
|
.long("remove")
|
|
|
|
.help("Remove the tasks added with 'cargo dev setup vscode-tasks'")
|
|
|
|
.required(false),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("force-override")
|
2021-07-01 11:17:38 -05:00
|
|
|
.long("force-override")
|
2022-06-04 06:34:07 -05:00
|
|
|
.short('f')
|
2021-07-01 11:17:38 -05:00
|
|
|
.help("Forces the override of existing vscode tasks")
|
|
|
|
.required(false),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("remove")
|
2021-07-01 11:17:38 -05:00
|
|
|
.about("Support for undoing changes done by the setup command")
|
2022-06-04 06:34:07 -05:00
|
|
|
.arg_required_else_help(true)
|
2022-06-16 10:39:06 -05:00
|
|
|
.subcommands([
|
|
|
|
Command::new("git-hook").about("Remove any existing pre-commit git hook"),
|
|
|
|
Command::new("vscode-tasks").about("Remove any existing vscode tasks"),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("intellij").about("Removes rustc source paths added via `cargo dev setup intellij`"),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("serve")
|
2020-10-09 05:45:29 -05:00
|
|
|
.about("Launch a local 'ALL the Clippy Lints' website in a browser")
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("port")
|
2020-10-09 05:45:29 -05:00
|
|
|
.long("port")
|
2022-06-04 06:34:07 -05:00
|
|
|
.short('p')
|
2020-10-09 05:45:29 -05:00
|
|
|
.help("Local port for the http server")
|
|
|
|
.default_value("8000")
|
2022-06-16 10:39:06 -05:00
|
|
|
.value_parser(clap::value_parser!(u16)),
|
|
|
|
Arg::new("lint").help("Which lint's page to load initially (optional)"),
|
|
|
|
]),
|
2022-06-04 06:34:07 -05:00
|
|
|
Command::new("lint")
|
2022-04-07 12:39:59 -05:00
|
|
|
.about("Manually run clippy on a file or package")
|
|
|
|
.after_help(indoc! {"
|
|
|
|
EXAMPLES
|
|
|
|
Lint a single file:
|
|
|
|
cargo dev lint tests/ui/attrs.rs
|
|
|
|
|
|
|
|
Lint a package directory:
|
|
|
|
cargo dev lint tests/ui-cargo/wildcard_dependencies/fail
|
|
|
|
cargo dev lint ~/my-project
|
2022-05-21 06:24:00 -05:00
|
|
|
|
|
|
|
Run rustfix:
|
|
|
|
cargo dev lint ~/my-project -- --fix
|
|
|
|
|
|
|
|
Set lint levels:
|
|
|
|
cargo dev lint file.rs -- -W clippy::pedantic
|
|
|
|
cargo dev lint ~/my-project -- -- -W clippy::pedantic
|
2022-04-07 12:39:59 -05:00
|
|
|
"})
|
2022-06-16 10:39:06 -05:00
|
|
|
.args([
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("path")
|
2021-12-06 05:33:31 -06:00
|
|
|
.required(true)
|
2022-04-07 12:39:59 -05:00
|
|
|
.help("The path to a file or package directory to lint"),
|
2022-06-04 06:34:07 -05:00
|
|
|
Arg::new("args")
|
2022-06-16 10:39:06 -05:00
|
|
|
.action(ArgAction::Append)
|
2022-05-21 06:24:00 -05:00
|
|
|
.help("Pass extra arguments to cargo/clippy-driver"),
|
2022-06-16 10:39:06 -05:00
|
|
|
]),
|
|
|
|
Command::new("rename_lint").about("Renames the given lint").args([
|
|
|
|
Arg::new("old_name")
|
|
|
|
.index(1)
|
|
|
|
.required(true)
|
|
|
|
.help("The name of the lint to rename"),
|
|
|
|
Arg::new("new_name")
|
|
|
|
.index(2)
|
|
|
|
.required_unless_present("uplift")
|
|
|
|
.help("The new name of the lint"),
|
|
|
|
Arg::new("uplift")
|
|
|
|
.long("uplift")
|
|
|
|
.help("This lint will be uplifted into rustc"),
|
|
|
|
]),
|
2022-06-30 03:50:09 -05:00
|
|
|
Command::new("deprecate").about("Deprecates the given lint").args([
|
|
|
|
Arg::new("name")
|
|
|
|
.index(1)
|
|
|
|
.required(true)
|
|
|
|
.help("The name of the lint to deprecate"),
|
|
|
|
Arg::new("reason")
|
|
|
|
.long("reason")
|
|
|
|
.short('r')
|
|
|
|
.required(false)
|
|
|
|
.takes_value(true)
|
|
|
|
.help("The reason for deprecation"),
|
|
|
|
]),
|
2022-06-16 10:39:06 -05:00
|
|
|
])
|
2021-03-12 08:30:50 -06:00
|
|
|
.get_matches()
|
2018-07-17 15:50:17 -05:00
|
|
|
}
|