14
14
use itertools:: Itertools ;
15
15
use lazy_static:: lazy_static;
16
16
use regex:: Regex ;
17
+ use walkdir:: WalkDir ;
17
18
use std:: collections:: HashMap ;
18
19
use std:: ffi:: OsStr ;
19
20
use std:: fs;
@@ -35,6 +36,7 @@ lazy_static! {
35
36
pub static ref DOCS_LINK : String = "https://rust-lang-nursery.github.io/rust-clippy/master/index.html" . to_string( ) ;
36
37
}
37
38
39
+ /// Lint data parsed from the Clippy source code.
38
40
#[ derive( Clone , PartialEq , Debug ) ]
39
41
pub struct Lint {
40
42
pub name : String ,
@@ -66,11 +68,12 @@ impl Lint {
66
68
}
67
69
}
68
70
71
+ /// Gathers all files in `src/clippy_lints` and gathers all lints inside
69
72
pub fn gather_all ( ) -> impl Iterator < Item =Lint > {
70
73
lint_files ( ) . flat_map ( |f| gather_from_file ( & f) )
71
74
}
72
75
73
- fn gather_from_file ( dir_entry : & fs :: DirEntry ) -> impl Iterator < Item =Lint > {
76
+ fn gather_from_file ( dir_entry : & walkdir :: DirEntry ) -> impl Iterator < Item =Lint > {
74
77
let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
75
78
let mut content = String :: new ( ) ;
76
79
file. read_to_string ( & mut content) . unwrap ( ) ;
@@ -89,9 +92,11 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
89
92
}
90
93
91
94
/// Collects all .rs files in the `clippy_lints/src` directory
92
- fn lint_files ( ) -> impl Iterator < Item =fs:: DirEntry > {
93
- fs:: read_dir ( "../clippy_lints/src" )
94
- . unwrap ( )
95
+ fn lint_files ( ) -> impl Iterator < Item =walkdir:: DirEntry > {
96
+ // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
97
+ // Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
98
+ WalkDir :: new ( "../clippy_lints/src" )
99
+ . into_iter ( )
95
100
. filter_map ( |f| f. ok ( ) )
96
101
. filter ( |f| f. path ( ) . extension ( ) == Some ( OsStr :: new ( "rs" ) ) )
97
102
}
0 commit comments