@@ -38,15 +38,20 @@ impl<T> Context for io::Result<T> {
3838pub fn create (
3939 pass : Option < & String > ,
4040 lint_name : Option < & String > ,
41- category : Option < & String > ,
42- ty : Option < & String > ,
41+ category : Option < & str > ,
42+ mut ty : Option < & str > ,
4343 msrv : bool ,
4444) -> 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+
4550 let lint = LintData {
4651 pass : pass. map_or ( "" , String :: as_str) ,
4752 name : lint_name. expect ( "`name` argument is validated by clap" ) ,
4853 category : category. expect ( "`category` argument is validated by clap" ) ,
49- ty : ty . map ( String :: as_str ) ,
54+ ty,
5055 project_root : clippy_project_root ( ) ,
5156 } ;
5257
@@ -95,7 +100,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
95100 create_project_layout ( lint. name , & test_dir, "fail" , "Content that triggers the lint goes here" ) ?;
96101 create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" ) ?;
97102
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`" ) ;
99104 } else {
100105 let test_path = format ! ( "tests/ui/{}.rs" , lint. name) ;
101106 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
341346 "Lints of type `cargo` must have the `cargo` category"
342347 ) ,
343348 _ if lint. category == "cargo" => panic ! ( "Lints of category `cargo` must have the `cargo` type" ) ,
344- _ => { }
349+ _ => { } ,
345350 }
346351
347352 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
405410
406411 write_file ( lint_file_path. as_path ( ) , lint_file_contents) ?;
407412 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+ ) ;
409417
410418 Ok ( ( ) )
411419}
0 commit comments