Merge pull request #1100 from epage/invert

fix(cli): Allow negative expressions in extend-exclude
This commit is contained in:
Ed Page 2024-09-16 15:01:39 -04:00 committed by GitHub
commit c4a6592239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 8 deletions

View file

@ -241,27 +241,35 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
walk.sort_by_file_name(|a, b| a.cmp(b)); walk.sort_by_file_name(|a, b| a.cmp(b));
} }
if !walk_policy.extend_exclude.is_empty() { 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() { for pattern in walk_policy.extend_exclude.iter() {
overrides ignores
.add(&format!("!{pattern}")) .add_line(None, pattern)
.with_code(proc_exit::sysexits::CONFIG_ERR)?; .with_code(proc_exit::sysexits::CONFIG_ERR)?;
} }
let overrides = overrides let ignores = ignores.build().with_code(proc_exit::sysexits::CONFIG_ERR)?;
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
if args.force_exclude { if args.force_exclude {
let mut ancestors = path.ancestors().collect::<Vec<_>>(); let mut ancestors = path.ancestors().collect::<Vec<_>>();
ancestors.reverse(); ancestors.reverse();
for path in ancestors { for path in ancestors {
match overrides.matched(path, path.is_dir()) { match ignores.matched(path, path.is_dir()) {
ignore::Match::None => {} ignore::Match::None => {}
ignore::Match::Ignore(_) => continue 'path, ignore::Match::Ignore(_) => continue 'path,
ignore::Match::Whitelist(_) => break, 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 // HACK: Diff doesn't handle mixing content

View file

@ -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

View file

@ -0,0 +1,2 @@
hte

View 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