Use `WalkDir` to also gather from subdirectories

`fs::read_dir` does not recurse into subdirectories.
This commit is contained in:
Philipp Hansch 2018-10-09 08:08:50 +02:00
parent 0f4b13bc1b
commit 7da97a94df
No known key found for this signature in database
GPG Key ID: B6FA06A6E0E2665B
2 changed files with 6 additions and 4 deletions

View File

@ -9,3 +9,4 @@ clap = "~2.32"
itertools = "0.7"
regex = "1"
lazy_static = "1.0"
walkdir = "2"

View File

@ -14,6 +14,7 @@
use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
use walkdir::WalkDir;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs;
@ -70,7 +71,7 @@ pub fn gather_all() -> impl Iterator<Item=Lint> {
lint_files().flat_map(|f| gather_from_file(&f))
}
fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> {
fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
let mut file = fs::File::open(dir_entry.path()).unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
@ -89,9 +90,9 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
}
/// Collects all .rs files in the `clippy_lints/src` directory
fn lint_files() -> impl Iterator<Item=fs::DirEntry> {
fs::read_dir("../clippy_lints/src")
.unwrap()
fn lint_files() -> impl Iterator<Item=walkdir::DirEntry> {
WalkDir::new("../clippy_lints/src")
.into_iter()
.filter_map(|f| f.ok())
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
}