From ad3538f7199c880c450a1ea0b5b465c187cece5c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 16 Sep 2024 13:37:31 -0500 Subject: [PATCH] refactor(cli): Switch from Overrides to Gitignore Avoid any double negatives that can cause confusion --- crates/typos-cli/src/bin/typos-cli/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index 81e4d35da..9dd8773d4 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -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::>(); 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, } }); }