From f31937043dbd8a10309ad742cd9e1a49721a09e5 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 26 Jul 2022 19:32:34 -0400 Subject: [PATCH] Implicitly set `--type=cargo` when using `--category=cargo` --- clippy_dev/src/main.rs | 4 ++-- clippy_dev/src/new_lint.rs | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 2008942d087..a417d3dd8a4 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -36,8 +36,8 @@ fn main() { match new_lint::create( matches.get_one::("pass"), matches.get_one::("name"), - matches.get_one::("category"), - matches.get_one::("type"), + matches.get_one::("category").map(String::as_str), + matches.get_one::("type").map(String::as_str), matches.contains_id("msrv"), ) { Ok(_) => update_lints::update(update_lints::UpdateMode::Change), diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index 4eea25b66de..03d2ef3d19e 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -38,15 +38,20 @@ fn context>(self, text: C) -> Self { pub fn create( pass: Option<&String>, lint_name: Option<&String>, - category: Option<&String>, - ty: Option<&String>, + category: Option<&str>, + mut ty: Option<&str>, msrv: bool, ) -> io::Result<()> { + if category == Some("cargo") && ty.is_none() { + // `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo` + ty = Some("cargo"); + } + let lint = LintData { pass: pass.map_or("", String::as_str), name: lint_name.expect("`name` argument is validated by clap"), category: category.expect("`category` argument is validated by clap"), - ty: ty.map(String::as_str), + ty, project_root: clippy_project_root(), }; @@ -95,7 +100,7 @@ fn create_project_layout>(lint_name: &str, location: P, case: & create_project_layout(lint.name, &test_dir, "fail", "Content that triggers the lint goes here")?; create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint")?; - println!("Generated test directories: `{}`, `{}`", format!("{}/pass", relative_test_dir), format!("{}/fail", relative_test_dir)); + println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`"); } else { let test_path = format!("tests/ui/{}.rs", lint.name); let test_contents = get_test_file_contents(lint.name, None); @@ -341,7 +346,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R "Lints of type `cargo` must have the `cargo` category" ), _ if lint.category == "cargo" => panic!("Lints of category `cargo` must have the `cargo` type"), - _ => {} + _ => {}, } let ty_dir = lint.project_root.join(format!("clippy_lints/src/{}", ty)); @@ -405,7 +410,10 @@ pub(super) fn check(cx: &{context_import}) {{ write_file(lint_file_path.as_path(), lint_file_contents)?; println!("Generated lint file: `clippy_lints/src/{}/{}.rs`", ty, lint.name); - println!("Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!", lint.name, ty); + println!( + "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!", + lint.name, ty + ); Ok(()) }