Skip to content

Commit 7da97a9

Browse files
committed
Use WalkDir to also gather from subdirectories
`fs::read_dir` does not recurse into subdirectories.
1 parent 0f4b13b commit 7da97a9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ clap = "~2.32"
99
itertools = "0.7"
1010
regex = "1"
1111
lazy_static = "1.0"
12+
walkdir = "2"

clippy_dev/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use itertools::Itertools;
1515
use lazy_static::lazy_static;
1616
use regex::Regex;
17+
use walkdir::WalkDir;
1718
use std::collections::HashMap;
1819
use std::ffi::OsStr;
1920
use std::fs;
@@ -70,7 +71,7 @@ pub fn gather_all() -> impl Iterator<Item=Lint> {
7071
lint_files().flat_map(|f| gather_from_file(&f))
7172
}
7273

73-
fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> {
74+
fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
7475
let mut file = fs::File::open(dir_entry.path()).unwrap();
7576
let mut content = String::new();
7677
file.read_to_string(&mut content).unwrap();
@@ -89,9 +90,9 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
8990
}
9091

9192
/// 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()
93+
fn lint_files() -> impl Iterator<Item=walkdir::DirEntry> {
94+
WalkDir::new("../clippy_lints/src")
95+
.into_iter()
9596
.filter_map(|f| f.ok())
9697
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
9798
}

0 commit comments

Comments
 (0)