Skip to content

Commit 0db7a7f

Browse files
committed
replace walkdir with ripgreps ignore crate
1 parent 37d4252 commit 0db7a7f

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ lto = true
6363
[dev-dependencies]
6464
regex = "1"
6565
once_cell = "1"
66-
walkdir = "2"
66+
ignore = "0.4"
6767

6868
[package.metadata.release]
6969
dev-version = false

src/tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ pub fn get_cargo_workspace() -> &'static Path {
2727

2828
pub fn walk_dir<'a>(
2929
root: &'_ Path,
30-
skip: &'a [impl AsRef<OsStr>],
31-
ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + 'static,
32-
) -> impl Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>> + 'a {
33-
walkdir::WalkDir::new(root)
34-
.into_iter()
30+
skip: &'static [impl AsRef<OsStr> + Send + Sync + 'a],
31+
ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + Sync + Send + 'static,
32+
) -> impl Iterator<Item = Result<ignore::DirEntry, ignore::Error>> {
33+
ignore::WalkBuilder::new(root)
3534
.filter_entry(move |e| {
3635
if skip
3736
.iter()
3837
.map(|s| -> &std::ffi::OsStr { s.as_ref() })
3938
.any(|dir| e.file_name() == dir)
4039
{
4140
return false;
42-
} else if e.file_type().is_dir() {
41+
} else if e.file_type().map_or(false, |f| f.is_dir()) {
4342
return true;
4443
}
4544
ext(e.path().extension())
4645
})
46+
.build()
4747
}
4848

4949
#[test]
@@ -134,9 +134,10 @@ release: {version}
134134
fn check_newlines() -> crate::Result<()> {
135135
for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
136136
let file = file?;
137-
if !file.file_type().is_file() {
137+
if !file.file_type().map_or(true, |f| f.is_file()) {
138138
continue;
139139
}
140+
eprintln!("File: {:?}", file.path());
140141
assert!(
141142
crate::file::read(file.path())
142143
.unwrap_or_else(|_| String::from("\n"))

src/tests/toml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
3030

3131
for dir_entry in walk {
3232
let dir_entry = dir_entry?;
33-
if dir_entry.file_type().is_dir() {
33+
if dir_entry.file_type().map_or(true, |f| f.is_dir()) {
3434
continue;
3535
}
3636
eprintln!("File: {:?}", dir_entry.path());

0 commit comments

Comments
 (0)