Skip to content

Commit b972394

Browse files
committed
refcctor check_diff
1 parent e7ee88d commit b972394

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

check_diff/src/lib.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,35 @@ pub fn compile_rustfmt(
349349
});
350350
}
351351

352-
pub fn check_diff(config: Option<Vec<String>>, runners: CheckDiffRunners) -> i32 {
352+
fn search_for_rs_files(repo: &Path) -> impl Iterator<Item = PathBuf> {
353+
return WalkDir::new(repo)
354+
.into_iter()
355+
.filter_map(|e| e.ok())
356+
.filter(|entry| {
357+
let path = entry.path();
358+
return path.is_file() && path.extension().map_or(false, |ext| ext == "rs");
359+
})
360+
.map(|entry| entry.into_path());
361+
}
362+
363+
pub fn check_diff(config: Option<Vec<String>>, runners: CheckDiffRunners, repo: &Path) -> i32 {
353364
let mut errors = 0;
354-
for entry in WalkDir::new(".").into_iter().filter_map(|e| e.ok()) {
355-
let path = entry.path();
356-
if path.is_file() && path.extension().map_or(false, |ext| ext == "rs") {
357-
match runners.create_diff(path, &config) {
358-
Ok(diff) => {
359-
if !diff.is_empty() {
360-
eprint!("{diff}");
361-
errors += 1;
362-
}
363-
}
364-
Err(e) => {
365-
eprintln!("Error creating diff for {:?}: {:?}", path.display(), e);
366-
errors += 1;
367-
}
365+
search_for_rs_files(repo).for_each(|file| match runners.create_diff(file.as_path(), &config) {
366+
Ok(diff) => {
367+
if !diff.is_empty() {
368+
eprint!("{diff}");
369+
errors += 1;
368370
}
369371
}
370-
}
372+
Err(e) => {
373+
eprintln!(
374+
"Error creating diff for {:?}: {:?}",
375+
file.as_path().display(),
376+
e
377+
);
378+
errors += 1;
379+
}
380+
});
381+
371382
return errors;
372383
}

check_diff/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ fn main() -> Result<(), CheckDiffError> {
3333
args.commit_hash,
3434
)?;
3535

36-
let _ = check_diff(args.rustfmt_config, check_diff_runners);
36+
// TODO: currently using same tmp dir path for sake of compilation
37+
let _ = check_diff(args.rustfmt_config, check_diff_runners, tmp_dir.path());
3738

3839
Ok(())
3940
}

0 commit comments

Comments
 (0)