@@ -38,15 +38,20 @@ impl<T> Context for io::Result<T> {
38
38
pub fn create (
39
39
pass : Option < & String > ,
40
40
lint_name : Option < & String > ,
41
- category : Option < & String > ,
42
- ty : Option < & String > ,
41
+ category : Option < & str > ,
42
+ mut ty : Option < & str > ,
43
43
msrv : bool ,
44
44
) -> io:: Result < ( ) > {
45
+ if category == Some ( "cargo" ) && ty. is_none ( ) {
46
+ // `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo`
47
+ ty = Some ( "cargo" ) ;
48
+ }
49
+
45
50
let lint = LintData {
46
51
pass : pass. map_or ( "" , String :: as_str) ,
47
52
name : lint_name. expect ( "`name` argument is validated by clap" ) ,
48
53
category : category. expect ( "`category` argument is validated by clap" ) ,
49
- ty : ty . map ( String :: as_str ) ,
54
+ ty,
50
55
project_root : clippy_project_root ( ) ,
51
56
} ;
52
57
@@ -95,7 +100,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
95
100
create_project_layout ( lint. name , & test_dir, "fail" , "Content that triggers the lint goes here" ) ?;
96
101
create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" ) ?;
97
102
98
- println ! ( "Generated test directories: `{} `, `{}`" , format! ( "{}/pass" , relative_test_dir) , format! ( "{ }/fail" , relative_test_dir ) ) ;
103
+ println ! ( "Generated test directories: `{relative_test_dir}/pass `, `{relative_test_dir}/fail`" ) ;
99
104
} else {
100
105
let test_path = format ! ( "tests/ui/{}.rs" , lint. name) ;
101
106
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
341
346
"Lints of type `cargo` must have the `cargo` category"
342
347
) ,
343
348
_ if lint. category == "cargo" => panic ! ( "Lints of category `cargo` must have the `cargo` type" ) ,
344
- _ => { }
349
+ _ => { } ,
345
350
}
346
351
347
352
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
405
410
406
411
write_file ( lint_file_path. as_path ( ) , lint_file_contents) ?;
407
412
println ! ( "Generated lint file: `clippy_lints/src/{}/{}.rs`" , ty, lint. name) ;
408
- println ! ( "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!" , lint. name, ty) ;
413
+ println ! (
414
+ "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!" ,
415
+ lint. name, ty
416
+ ) ;
409
417
410
418
Ok ( ( ) )
411
419
}
0 commit comments