@@ -72,6 +72,19 @@ impl Lint {
72
72
}
73
73
}
74
74
75
+ /// Updates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
76
+ pub fn gen_modules_list ( lints : Vec < Lint > ) -> Vec < String > {
77
+ lints. into_iter ( )
78
+ . filter_map ( |l| {
79
+ if l. is_internal ( ) || l. deprecation . is_some ( ) { None } else { Some ( l. module ) }
80
+ } )
81
+ . unique ( )
82
+ . map ( |module| {
83
+ format ! ( "pub mod {};" , module)
84
+ } )
85
+ . sorted ( )
86
+ }
87
+
75
88
/// Generates the list of lint links at the bottom of the README
76
89
pub fn gen_changelog_lint_list ( lints : Vec < Lint > ) -> Vec < String > {
77
90
let mut lint_list_sorted: Vec < Lint > = lints;
@@ -113,7 +126,13 @@ fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
113
126
let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
114
127
let mut content = String :: new ( ) ;
115
128
file. read_to_string ( & mut content) . unwrap ( ) ;
116
- parse_contents ( & content, dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) )
129
+ let mut filename = dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
130
+ // If the lints are stored in mod.rs, we get the module name from
131
+ // the containing directory:
132
+ if filename == "mod" {
133
+ filename = dir_entry. path ( ) . parent ( ) . unwrap ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( )
134
+ }
135
+ parse_contents ( & content, filename)
117
136
}
118
137
119
138
fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item =Lint > {
@@ -215,7 +234,7 @@ pub fn replace_region_in_text<F>(text: &str, start: &str, end: &str, replace_sta
215
234
// This happens if the provided regex in `clippy_dev/src/main.rs` is not found in the
216
235
// given text or file. Most likely this is an error on the programmer's side and the Regex
217
236
// is incorrect.
218
- println ! ( "regex {:?} not found. You may have to update it." , start) ;
237
+ eprintln ! ( "error: regex ` {:?}` not found. You may have to update it." , start) ;
219
238
}
220
239
new_lines. join ( "\n " )
221
240
}
@@ -356,3 +375,18 @@ fn test_gen_deprecated() {
356
375
] ;
357
376
assert_eq ! ( expected, gen_deprecated( & lints) ) ;
358
377
}
378
+
379
+ #[ test]
380
+ fn test_gen_modules_list ( ) {
381
+ let lints = vec ! [
382
+ Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
383
+ Lint :: new( "should_assert_eq2" , "group2" , "abc" , Some ( "abc" ) , "deprecated" ) ,
384
+ Lint :: new( "incorrect_internal" , "internal_style" , "abc" , None , "another_module" ) ,
385
+ Lint :: new( "incorrect_internal" , "internal_style" , "abc" , None , "module_name" ) ,
386
+ ] ;
387
+ let expected = vec ! [
388
+ "pub mod another_module;\n " . to_string( ) ,
389
+ "pub mod module_name;\n " . to_string( ) ,
390
+ ] ;
391
+ assert_eq ! ( expected, gen_modules_list( lints) ) ;
392
+ }
0 commit comments