@@ -62,11 +62,14 @@ pub fn create(
62
62
63
63
fn create_lint ( lint : & LintData < ' _ > , enable_msrv : bool ) -> io:: Result < ( ) > {
64
64
if let Some ( ty) = lint. ty {
65
- generate_from_ty ( lint, enable_msrv, ty)
65
+ create_lint_for_ty ( lint, enable_msrv, ty)
66
66
} else {
67
67
let lint_contents = get_lint_file_contents ( lint, enable_msrv) ;
68
68
let lint_path = format ! ( "clippy_lints/src/{}.rs" , lint. name) ;
69
- write_file ( lint. project_root . join ( & lint_path) , lint_contents. as_bytes ( ) )
69
+ write_file ( lint. project_root . join ( & lint_path) , lint_contents. as_bytes ( ) ) ?;
70
+ println ! ( "Generated lint file: `{}`" , lint_path) ;
71
+
72
+ Ok ( ( ) )
70
73
}
71
74
}
72
75
@@ -86,16 +89,22 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
86
89
87
90
if lint. category == "cargo" {
88
91
let relative_test_dir = format ! ( "tests/ui-cargo/{}" , lint. name) ;
89
- let test_dir = lint. project_root . join ( relative_test_dir) ;
92
+ let test_dir = lint. project_root . join ( & relative_test_dir) ;
90
93
fs:: create_dir ( & test_dir) ?;
91
94
92
95
create_project_layout ( lint. name , & test_dir, "fail" , "Content that triggers the lint goes here" ) ?;
93
- create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" )
96
+ create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" ) ?;
97
+
98
+ println ! ( "Generated test directories: `{}`, `{}`" , format!( "{}/pass" , relative_test_dir) , format!( "{}/fail" , relative_test_dir) ) ;
94
99
} else {
95
100
let test_path = format ! ( "tests/ui/{}.rs" , lint. name) ;
96
101
let test_contents = get_test_file_contents ( lint. name , None ) ;
97
- write_file ( lint. project_root . join ( test_path) , test_contents)
102
+ write_file ( lint. project_root . join ( & test_path) , test_contents) ?;
103
+
104
+ println ! ( "Generated test file: `{}`" , test_path) ;
98
105
}
106
+
107
+ Ok ( ( ) )
99
108
}
100
109
101
110
fn add_lint ( lint : & LintData < ' _ > , enable_msrv : bool ) -> io:: Result < ( ) > {
@@ -325,12 +334,14 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
325
334
)
326
335
}
327
336
328
- fn generate_from_ty ( lint : & LintData < ' _ > , enable_msrv : bool , ty : & str ) -> io:: Result < ( ) > {
329
- if ty == "cargo" {
330
- assert_eq ! (
337
+ fn create_lint_for_ty ( lint : & LintData < ' _ > , enable_msrv : bool , ty : & str ) -> io:: Result < ( ) > {
338
+ match ty {
339
+ "cargo" => assert_eq ! (
331
340
lint. category, "cargo" ,
332
341
"Lints of type `cargo` must have the `cargo` category"
333
- ) ;
342
+ ) ,
343
+ _ if lint. category == "cargo" => panic ! ( "Lints of category `cargo` must have the `cargo` type" ) ,
344
+ _ => { }
334
345
}
335
346
336
347
let ty_dir = lint. project_root . join ( format ! ( "clippy_lints/src/{}" , ty) ) ;
@@ -392,7 +403,9 @@ fn generate_from_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::Res
392
403
) ;
393
404
}
394
405
395
- write_file ( lint_file_path, lint_file_contents) ?;
406
+ write_file ( lint_file_path. as_path ( ) , lint_file_contents) ?;
407
+ 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) ;
396
409
397
410
Ok ( ( ) )
398
411
}
0 commit comments