mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 15:42:23 -05:00
Merge pull request #1100 from epage/invert
fix(cli): Allow negative expressions in extend-exclude
This commit is contained in:
commit
c4a6592239
6 changed files with 46 additions and 8 deletions
|
@ -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::<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,
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
hte
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
hte
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
hte
|
||||
|
12
crates/typos-cli/tests/cmd/extend-exclude-inverted.toml
Normal file
12
crates/typos-cli/tests/cmd/extend-exclude-inverted.toml
Normal file
|
@ -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
|
Loading…
Reference in a new issue