about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSerial <69764315+Serial-ATA@users.noreply.github.com>2022-07-26 19:32:34 -0400
committerSerial <69764315+Serial-ATA@users.noreply.github.com>2022-07-26 19:32:34 -0400
commitf31937043dbd8a10309ad742cd9e1a49721a09e5 (patch)
tree9209567c534099d24b65475132948f2fea39ceaa
parentc8ee8c30f00214fcc3849d3124501e5e9768bb53 (diff)
downloadrust-f31937043dbd8a10309ad742cd9e1a49721a09e5.tar.gz
rust-f31937043dbd8a10309ad742cd9e1a49721a09e5.zip
Implicitly set `--type=cargo` when using `--category=cargo`
-rw-r--r--clippy_dev/src/main.rs4
-rw-r--r--clippy_dev/src/new_lint.rs20
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::<String>("pass"),
                 matches.get_one::<String>("name"),
-                matches.get_one::<String>("category"),
-                matches.get_one::<String>("type"),
+                matches.get_one::<String>("category").map(String::as_str),
+                matches.get_one::<String>("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 @@ impl<T> Context for io::Result<T> {
 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_test(lint: &LintData<'_>) -> io::Result<()> {
         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 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
 
     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(())
 }