diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index ca0638a..9dd8773 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -241,27 +241,35 @@ 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(&format!("!{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, } } } - walk.overrides(overrides); + 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 = ignores.matched(path, is_dir); + log::debug!("match({path:?}, {is_dir}) == {matched:?}"); + match matched { + ignore::Match::None => true, + ignore::Match::Ignore(_) => false, + ignore::Match::Whitelist(_) => true, + } + }); } // HACK: Diff doesn't handle mixing content diff --git a/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/_typos.toml b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/_typos.toml new file mode 100644 index 0000000..6e5c8fd --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/_typos.toml @@ -0,0 +1,12 @@ +[files] +extend-exclude = [ + "*", + "!checked/", + "!checked/**", +] +ignore-hidden = true +ignore-files = true +ignore-dot = true +ignore-vcs = true +ignore-global = true +ignore-parent = true diff --git a/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/checked/file.txt b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/checked/file.txt new file mode 100644 index 0000000..e7cbd35 --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/checked/file.txt @@ -0,0 +1,2 @@ +hte + diff --git a/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/file.txt b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/file.txt new file mode 100644 index 0000000..e7cbd35 --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/file.txt @@ -0,0 +1,2 @@ +hte + diff --git a/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/unchecked/file.txt b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/unchecked/file.txt new file mode 100644 index 0000000..e7cbd35 --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-exclude-inverted.in/unchecked/file.txt @@ -0,0 +1,2 @@ +hte + diff --git a/crates/typos-cli/tests/cmd/extend-exclude-inverted.toml b/crates/typos-cli/tests/cmd/extend-exclude-inverted.toml new file mode 100644 index 0000000..b8e837b --- /dev/null +++ b/crates/typos-cli/tests/cmd/extend-exclude-inverted.toml @@ -0,0 +1,12 @@ +bin.name = "typos" +stdin = "" +stdout = """ +error: `hte` should be `the` + --> ./checked/file.txt:1:1 + | +1 | hte + | ^^^ + | +""" +stderr = "" +status.code = 2