Skip to content

Commit

Permalink
refactor(cli): Switch from Overrides to Gitignore
Browse files Browse the repository at this point in the history
Avoid any double negatives that can cause confusion
  • Loading branch information
epage committed Sep 16, 2024
1 parent d9b55f9 commit ad3538f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
});
}
Expand Down

0 comments on commit ad3538f

Please sign in to comment.