@@ -71,6 +71,32 @@ impl Lint {
71
71
}
72
72
}
73
73
74
+ /// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
75
+ pub fn gen_lint_group_list ( lints : Vec < Lint > ) -> Vec < String > {
76
+ lints. into_iter ( )
77
+ . filter_map ( |l| {
78
+ if l. is_internal ( ) || l. deprecation . is_some ( ) {
79
+ None
80
+ } else {
81
+ Some ( format ! ( " {}::{}," , l. module, l. name. to_uppercase( ) ) )
82
+ }
83
+ } )
84
+ . sorted ( )
85
+ }
86
+
87
+ /// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
88
+ pub fn gen_modules_list ( lints : Vec < Lint > ) -> Vec < String > {
89
+ lints. into_iter ( )
90
+ . filter_map ( |l| {
91
+ if l. is_internal ( ) || l. deprecation . is_some ( ) { None } else { Some ( l. module ) }
92
+ } )
93
+ . unique ( )
94
+ . map ( |module| {
95
+ format ! ( "pub mod {};" , module)
96
+ } )
97
+ . sorted ( )
98
+ }
99
+
74
100
/// Generates the list of lint links at the bottom of the README
75
101
pub fn gen_changelog_lint_list ( lints : Vec < Lint > ) -> Vec < String > {
76
102
let mut lint_list_sorted: Vec < Lint > = lints;
@@ -112,7 +138,13 @@ fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
112
138
let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
113
139
let mut content = String :: new ( ) ;
114
140
file. read_to_string ( & mut content) . unwrap ( ) ;
115
- parse_contents ( & content, dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
141
+ let mut filename = dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
142
+ // If the lints are stored in mod.rs, we get the module name from
143
+ // the containing directory:
144
+ if filename == "mod" {
145
+ filename = dir_entry. path ( ) . parent ( ) . unwrap ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( )
146
+ }
147
+ parse_contents ( & content, filename)
116
148
}
117
149
118
150
fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item =Lint > {
@@ -214,7 +246,7 @@ pub fn replace_region_in_text<F>(text: &str, start: &str, end: &str, replace_sta
214
246
// This happens if the provided regex in `clippy_dev/src/main.rs` is not found in the
215
247
// given text or file. Most likely this is an error on the programmer's side and the Regex
216
248
// is incorrect.
217
- println ! ( "regex {:?} not found. You may have to update it." , start) ;
249
+ eprintln ! ( "error: regex ` {:?}` not found. You may have to update it." , start) ;
218
250
}
219
251
new_lines. join ( "\n " )
220
252
}
@@ -355,3 +387,33 @@ fn test_gen_deprecated() {
355
387
] ;
356
388
assert_eq ! ( expected, gen_deprecated( & lints) ) ;
357
389
}
390
+
391
+ #[ test]
392
+ fn test_gen_modules_list ( ) {
393
+ let lints = vec ! [
394
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
395
+ Lint :: new( "should_assert_eq2" , "group2" , "abc" , Some ( "abc" ) , "deprecated" ) ,
396
+ Lint :: new( "incorrect_stuff" , "group3" , "abc" , None , "another_module" ) ,
397
+ Lint :: new( "incorrect_internal" , "internal_style" , "abc" , None , "module_name" ) ,
398
+ ] ;
399
+ let expected = vec ! [
400
+ "pub mod another_module;" . to_string( ) ,
401
+ "pub mod module_name;" . to_string( ) ,
402
+ ] ;
403
+ assert_eq ! ( expected, gen_modules_list( lints) ) ;
404
+ }
405
+
406
+ #[ test]
407
+ fn test_gen_lint_group_list ( ) {
408
+ let lints = vec ! [
409
+ Lint :: new( "abc" , "group1" , "abc" , None , "module_name" ) ,
410
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
411
+ Lint :: new( "should_assert_eq2" , "group2" , "abc" , Some ( "abc" ) , "deprecated" ) ,
412
+ Lint :: new( "incorrect_internal" , "internal_style" , "abc" , None , "module_name" ) ,
413
+ ] ;
414
+ let expected = vec ! [
415
+ " module_name::ABC," . to_string( ) ,
416
+ " module_name::SHOULD_ASSERT_EQ," . to_string( ) ,
417
+ ] ;
418
+ assert_eq ! ( expected, gen_lint_group_list( lints) ) ;
419
+ }
0 commit comments