Include per-file ignore matches in debug logging (#2376)

This commit is contained in:
Charlie Marsh 2023-01-30 23:11:56 -05:00 committed by GitHub
parent 00495e8620
commit 6051a0c1c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 3 deletions

View File

@ -1,8 +1,10 @@
use std::fs::File;
use std::io::{BufReader, Read};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result};
use log::debug;
use path_absolutize::{path_dedot, Absolutize};
use rustc_hash::FxHashSet;
@ -34,10 +36,28 @@ pub(crate) fn ignores_from_path<'a>(
let (file_path, file_basename) = extract_path_names(path)?;
Ok(pattern_code_pairs
.iter()
.filter(|(absolute, basename, _)| {
basename.is_match(file_basename) || absolute.is_match(file_path)
.filter_map(|(absolute, basename, codes)| {
if basename.is_match(file_basename) {
debug!(
"Adding per-file ignores for {:?} due to basename match on {:?}: {:?}",
path,
basename.deref().glob().regex(),
&**codes
);
return Some(codes.iter());
}
if absolute.is_match(file_path) {
debug!(
"Adding per-file ignores for {:?} due to absolute match on {:?}: {:?}",
path,
absolute.deref().glob().regex(),
&**codes
);
return Some(codes.iter());
}
None
})
.flat_map(|(_, _, codes)| codes.iter())
.flatten()
.collect())
}