@@ -72,6 +72,19 @@ impl Lint {
7272 }
7373}
7474
75+ /// Generates 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+
7588/// Generates the list of lint links at the bottom of the README
7689pub fn gen_changelog_lint_list ( lints : Vec < Lint > ) -> Vec < String > {
7790 let mut lint_list_sorted: Vec < Lint > = lints;
@@ -113,7 +126,13 @@ fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
113126 let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
114127 let mut content = String :: new ( ) ;
115128 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)
117136}
118137
119138fn 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
215234 // This happens if the provided regex in `clippy_dev/src/main.rs` is not found in the
216235 // given text or file. Most likely this is an error on the programmer's side and the Regex
217236 // 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) ;
219238 }
220239 new_lines. join ( "\n " )
221240}
@@ -356,3 +375,18 @@ fn test_gen_deprecated() {
356375 ] ;
357376 assert_eq ! ( expected, gen_deprecated( & lints) ) ;
358377}
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