1414use itertools:: Itertools ;
1515use lazy_static:: lazy_static;
1616use regex:: Regex ;
17+ use walkdir:: WalkDir ;
1718use std:: collections:: HashMap ;
1819use std:: ffi:: OsStr ;
1920use std:: fs;
@@ -35,6 +36,7 @@ lazy_static! {
3536 pub static ref DOCS_LINK : String = "https://rust-lang-nursery.github.io/rust-clippy/master/index.html" . to_string( ) ;
3637}
3738
39+ /// Lint data parsed from the Clippy source code.
3840#[ derive( Clone , PartialEq , Debug ) ]
3941pub struct Lint {
4042 pub name : String ,
@@ -66,11 +68,12 @@ impl Lint {
6668 }
6769}
6870
71+ /// Gathers all files in `src/clippy_lints` and gathers all lints inside
6972pub fn gather_all ( ) -> impl Iterator < Item =Lint > {
7073 lint_files ( ) . flat_map ( |f| gather_from_file ( & f) )
7174}
7275
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 > {
7477 let mut file = fs:: File :: open ( dir_entry. path ( ) ) . unwrap ( ) ;
7578 let mut content = String :: new ( ) ;
7679 file. read_to_string ( & mut content) . unwrap ( ) ;
@@ -89,9 +92,11 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
8992}
9093
9194/// 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 ( )
95100 . filter_map ( |f| f. ok ( ) )
96101 . filter ( |f| f. path ( ) . extension ( ) == Some ( OsStr :: new ( "rs" ) ) )
97102}
0 commit comments