summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/clippy_dev
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/clippy_dev')
-rw-r--r--src/tools/clippy/clippy_dev/Cargo.toml2
-rw-r--r--src/tools/clippy/clippy_dev/src/main.rs127
-rw-r--r--src/tools/clippy/clippy_dev/src/new_lint.rs9
-rw-r--r--src/tools/clippy/clippy_dev/src/update_lints.rs6
4 files changed, 78 insertions, 66 deletions
diff --git a/src/tools/clippy/clippy_dev/Cargo.toml b/src/tools/clippy/clippy_dev/Cargo.toml
index 510c7e852..c3f8a782d 100644
--- a/src/tools/clippy/clippy_dev/Cargo.toml
+++ b/src/tools/clippy/clippy_dev/Cargo.toml
@@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
aho-corasick = "0.7"
-clap = "3.2"
+clap = "4.1.4"
indoc = "1.0"
itertools = "0.10.1"
opener = "0.5"
diff --git a/src/tools/clippy/clippy_dev/src/main.rs b/src/tools/clippy/clippy_dev/src/main.rs
index d3e036692..e2457e5a8 100644
--- a/src/tools/clippy/clippy_dev/src/main.rs
+++ b/src/tools/clippy/clippy_dev/src/main.rs
@@ -2,7 +2,7 @@
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
-use clap::{Arg, ArgAction, ArgMatches, Command, PossibleValue};
+use clap::{Arg, ArgAction, ArgMatches, Command};
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
use indoc::indoc;
@@ -11,22 +11,22 @@ fn main() {
match matches.subcommand() {
Some(("bless", matches)) => {
- bless::bless(matches.contains_id("ignore-timestamp"));
+ bless::bless(matches.get_flag("ignore-timestamp"));
},
Some(("dogfood", matches)) => {
dogfood::dogfood(
- matches.contains_id("fix"),
- matches.contains_id("allow-dirty"),
- matches.contains_id("allow-staged"),
+ matches.get_flag("fix"),
+ matches.get_flag("allow-dirty"),
+ matches.get_flag("allow-staged"),
);
},
Some(("fmt", matches)) => {
- fmt::run(matches.contains_id("check"), matches.contains_id("verbose"));
+ fmt::run(matches.get_flag("check"), matches.get_flag("verbose"));
},
Some(("update_lints", matches)) => {
- if matches.contains_id("print-only") {
+ if matches.get_flag("print-only") {
update_lints::print_lints();
- } else if matches.contains_id("check") {
+ } else if matches.get_flag("check") {
update_lints::update(update_lints::UpdateMode::Check);
} else {
update_lints::update(update_lints::UpdateMode::Change);
@@ -38,7 +38,7 @@ fn main() {
matches.get_one::<String>("name"),
matches.get_one::<String>("category").map(String::as_str),
matches.get_one::<String>("type").map(String::as_str),
- matches.contains_id("msrv"),
+ matches.get_flag("msrv"),
) {
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
Err(e) => eprintln!("Unable to create lint: {e}"),
@@ -46,7 +46,7 @@ fn main() {
},
Some(("setup", sub_command)) => match sub_command.subcommand() {
Some(("intellij", matches)) => {
- if matches.contains_id("remove") {
+ if matches.get_flag("remove") {
setup::intellij::remove_rustc_src();
} else {
setup::intellij::setup_rustc_src(
@@ -57,17 +57,17 @@ fn main() {
}
},
Some(("git-hook", matches)) => {
- if matches.contains_id("remove") {
+ if matches.get_flag("remove") {
setup::git_hook::remove_hook();
} else {
- setup::git_hook::install_hook(matches.contains_id("force-override"));
+ setup::git_hook::install_hook(matches.get_flag("force-override"));
}
},
Some(("vscode-tasks", matches)) => {
- if matches.contains_id("remove") {
+ if matches.get_flag("remove") {
setup::vscode::remove_tasks();
} else {
- setup::vscode::install_tasks(matches.contains_id("force-override"));
+ setup::vscode::install_tasks(matches.get_flag("force-override"));
}
},
_ => {},
@@ -91,7 +91,7 @@ fn main() {
Some(("rename_lint", matches)) => {
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");
+ let uplift = matches.get_flag("uplift");
update_lints::rename(old_name, new_name, uplift);
},
Some(("deprecate", matches)) => {
@@ -110,24 +110,37 @@ fn get_clap_config() -> ArgMatches {
Command::new("bless").about("bless the test output changes").arg(
Arg::new("ignore-timestamp")
.long("ignore-timestamp")
+ .action(ArgAction::SetTrue)
.help("Include files updated before clippy was built"),
),
Command::new("dogfood").about("Runs the dogfood test").args([
- Arg::new("fix").long("fix").help("Apply the suggestions when possible"),
+ Arg::new("fix")
+ .long("fix")
+ .action(ArgAction::SetTrue)
+ .help("Apply the suggestions when possible"),
Arg::new("allow-dirty")
.long("allow-dirty")
+ .action(ArgAction::SetTrue)
.help("Fix code even if the working directory has changes")
.requires("fix"),
Arg::new("allow-staged")
.long("allow-staged")
+ .action(ArgAction::SetTrue)
.help("Fix code even if the working directory has staged changes")
.requires("fix"),
]),
Command::new("fmt")
.about("Run rustfmt on all projects and tests")
.args([
- Arg::new("check").long("check").help("Use the rustfmt --check option"),
- Arg::new("verbose").short('v').long("verbose").help("Echo commands run"),
+ Arg::new("check")
+ .long("check")
+ .action(ArgAction::SetTrue)
+ .help("Use the rustfmt --check option"),
+ Arg::new("verbose")
+ .short('v')
+ .long("verbose")
+ .action(ArgAction::SetTrue)
+ .help("Echo commands run"),
]),
Command::new("update_lints")
.about("Updates lint registration and information from the source code")
@@ -140,13 +153,17 @@ fn get_clap_config() -> ArgMatches {
* all lints are registered in the lint store",
)
.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)",
- ),
+ Arg::new("print-only")
+ .long("print-only")
+ .action(ArgAction::SetTrue)
+ .help(
+ "Print a table of lints to STDOUT. \
+ This does not include deprecated and internal lints. \
+ (Does not modify any files)",
+ ),
Arg::new("check")
.long("check")
+ .action(ArgAction::SetTrue)
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
]),
Command::new("new_lint")
@@ -156,15 +173,13 @@ fn get_clap_config() -> ArgMatches {
.short('p')
.long("pass")
.help("Specify whether the lint runs during the early or late pass")
- .takes_value(true)
- .value_parser([PossibleValue::new("early"), PossibleValue::new("late")])
+ .value_parser(["early", "late"])
.conflicts_with("type")
.required_unless_present("type"),
Arg::new("name")
.short('n')
.long("name")
.help("Name of the new lint in snake case, ex: fn_too_long")
- .takes_value(true)
.required(true),
Arg::new("category")
.short('c')
@@ -172,25 +187,23 @@ fn get_clap_config() -> ArgMatches {
.help("What category the lint belongs to")
.default_value("nursery")
.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"),
- ])
- .takes_value(true),
- Arg::new("type")
- .long("type")
- .help("What directory the lint belongs in")
- .takes_value(true)
- .required(false),
- Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint"),
+ "style",
+ "correctness",
+ "suspicious",
+ "complexity",
+ "perf",
+ "pedantic",
+ "restriction",
+ "cargo",
+ "nursery",
+ "internal",
+ "internal_warn",
+ ]),
+ Arg::new("type").long("type").help("What directory the lint belongs in"),
+ Arg::new("msrv")
+ .long("msrv")
+ .action(ArgAction::SetTrue)
+ .help("Add MSRV config code to the lint"),
]),
Command::new("setup")
.about("Support for setting up your personal development environment")
@@ -201,13 +214,12 @@ fn get_clap_config() -> ArgMatches {
.args([
Arg::new("remove")
.long("remove")
- .help("Remove the dependencies added with 'cargo dev setup intellij'")
- .required(false),
+ .action(ArgAction::SetTrue)
+ .help("Remove the dependencies added with 'cargo dev setup intellij'"),
Arg::new("rustc-repo-path")
.long("repo-path")
.short('r')
.help("The path to a rustc repo that will be used for setting the dependencies")
- .takes_value(true)
.value_name("path")
.conflicts_with("remove")
.required(true),
@@ -217,26 +229,26 @@ fn get_clap_config() -> ArgMatches {
.args([
Arg::new("remove")
.long("remove")
- .help("Remove the pre-commit hook added with 'cargo dev setup git-hook'")
- .required(false),
+ .action(ArgAction::SetTrue)
+ .help("Remove the pre-commit hook added with 'cargo dev setup git-hook'"),
Arg::new("force-override")
.long("force-override")
.short('f')
- .help("Forces the override of an existing git pre-commit hook")
- .required(false),
+ .action(ArgAction::SetTrue)
+ .help("Forces the override of an existing git pre-commit hook"),
]),
Command::new("vscode-tasks")
.about("Add several tasks to vscode for formatting, validation and testing")
.args([
Arg::new("remove")
.long("remove")
- .help("Remove the tasks added with 'cargo dev setup vscode-tasks'")
- .required(false),
+ .action(ArgAction::SetTrue)
+ .help("Remove the tasks added with 'cargo dev setup vscode-tasks'"),
Arg::new("force-override")
.long("force-override")
.short('f')
- .help("Forces the override of existing vscode tasks")
- .required(false),
+ .action(ArgAction::SetTrue)
+ .help("Forces the override of existing vscode tasks"),
]),
]),
Command::new("remove")
@@ -295,6 +307,7 @@ fn get_clap_config() -> ArgMatches {
.help("The new name of the lint"),
Arg::new("uplift")
.long("uplift")
+ .action(ArgAction::SetTrue)
.help("This lint will be uplifted into rustc"),
]),
Command::new("deprecate").about("Deprecates the given lint").args([
@@ -305,8 +318,6 @@ fn get_clap_config() -> ArgMatches {
Arg::new("reason")
.long("reason")
.short('r')
- .required(false)
- .takes_value(true)
.help("The reason for deprecation"),
]),
])
diff --git a/src/tools/clippy/clippy_dev/src/new_lint.rs b/src/tools/clippy/clippy_dev/src/new_lint.rs
index ec7f1dd0d..420214d92 100644
--- a/src/tools/clippy/clippy_dev/src/new_lint.rs
+++ b/src/tools/clippy/clippy_dev/src/new_lint.rs
@@ -1,5 +1,6 @@
use crate::clippy_project_root;
use indoc::{formatdoc, writedoc};
+use std::fmt;
use std::fmt::Write as _;
use std::fs::{self, OpenOptions};
use std::io::prelude::*;
@@ -256,7 +257,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
)
});
- let _ = write!(result, "{}", get_lint_declaration(&name_upper, category));
+ let _: fmt::Result = write!(result, "{}", get_lint_declaration(&name_upper, category));
result.push_str(&if enable_msrv {
formatdoc!(
@@ -353,7 +354,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
let mut lint_file_contents = String::new();
if enable_msrv {
- let _ = writedoc!(
+ let _: fmt::Result = writedoc!(
lint_file_contents,
r#"
use clippy_utils::msrvs::{{self, Msrv}};
@@ -373,7 +374,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
name_upper = name_upper,
);
} else {
- let _ = writedoc!(
+ let _: fmt::Result = writedoc!(
lint_file_contents,
r#"
use rustc_lint::{{{context_import}, LintContext}};
@@ -521,7 +522,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
.chain(std::iter::once(&*lint_name_upper))
.filter(|s| !s.is_empty())
{
- let _ = write!(new_arr_content, "\n {ident},");
+ let _: fmt::Result = write!(new_arr_content, "\n {ident},");
}
new_arr_content.push('\n');
diff --git a/src/tools/clippy/clippy_dev/src/update_lints.rs b/src/tools/clippy/clippy_dev/src/update_lints.rs
index 837618c92..779e4d0e1 100644
--- a/src/tools/clippy/clippy_dev/src/update_lints.rs
+++ b/src/tools/clippy/clippy_dev/src/update_lints.rs
@@ -5,7 +5,7 @@ use itertools::Itertools;
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
use std::collections::{HashMap, HashSet};
use std::ffi::OsStr;
-use std::fmt::Write;
+use std::fmt::{self, Write};
use std::fs::{self, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Write as _};
use std::ops::Range;
@@ -691,7 +691,7 @@ fn gen_deprecated(lints: &[DeprecatedLint]) -> String {
let mut output = GENERATED_FILE_COMMENT.to_string();
output.push_str("{\n");
for lint in lints {
- let _ = write!(
+ let _: fmt::Result = write!(
output,
concat!(
" store.register_removed(\n",
@@ -726,7 +726,7 @@ fn gen_declared_lints<'a>(
if !is_public {
output.push_str(" #[cfg(feature = \"internal\")]\n");
}
- let _ = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
+ let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
}
output.push_str("];\n");