refactor(cli): Switch from Overrides to Gitignore

Avoid any double negatives that can cause confusion
This commit is contained in:
Ed Page 2024-09-16 13:37:31 -05:00
parent d9b55f966c
commit ad3538f719

View file

@ -241,20 +241,18 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
walk.sort_by_file_name(|a, b| a.cmp(b));
}
if !walk_policy.extend_exclude.is_empty() {
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
let mut ignores = ignore::gitignore::GitignoreBuilder::new(".");
for pattern in walk_policy.extend_exclude.iter() {
overrides
.add(pattern)
ignores
.add_line(None, pattern)
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
}
let overrides = overrides
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
let ignores = ignores.build().with_code(proc_exit::sysexits::CONFIG_ERR)?;
if args.force_exclude {
let mut ancestors = path.ancestors().collect::<Vec<_>>();
ancestors.reverse();
for path in ancestors {
match overrides.matched(path, path.is_dir()) {
match ignores.matched(path, path.is_dir()) {
ignore::Match::None => {}
ignore::Match::Ignore(_) => continue 'path,
ignore::Match::Whitelist(_) => break,
@ -264,12 +262,12 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
walk.filter_entry(move |entry| {
let path = entry.path();
let is_dir = entry.file_type().map(|t| t.is_dir()).unwrap_or(false);
let matched = overrides.matched(path, is_dir);
let matched = ignores.matched(path, is_dir);
log::debug!("match({path:?}, {is_dir}) == {matched:?}");
match matched {
ignore::Match::None => true,
ignore::Match::Ignore(_) => true,
ignore::Match::Whitelist(_) => false,
ignore::Match::Ignore(_) => false,
ignore::Match::Whitelist(_) => true,
}
});
}