Skip to content

Commit

Permalink
Merge pull request #869 from epage/exclude
Browse files Browse the repository at this point in the history
fix(cli): Respect force-exclude for simple exclude patterns
  • Loading branch information
epage authored Nov 6, 2023
2 parents 0d04ce9 + e24c694 commit f01cfa5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
};

// Note: file_list and args.path are mutually exclusive, enforced by clap
for path in file_list.as_ref().unwrap_or(&args.path) {
'path: for path in file_list.as_ref().unwrap_or(&args.path) {
// Note paths are passed through stdin, `-` is treated like a normal path
let cwd = if path == std::path::Path::new("-") {
if args.file_list.is_some() {
Expand Down Expand Up @@ -244,8 +244,14 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
if args.force_exclude {
if let ignore::Match::Ignore(_) = overrides.matched(path, path.is_dir()) {
continue;
let mut ancestors = path.ancestors().collect::<Vec<_>>();
ancestors.reverse();
for path in ancestors {
match overrides.matched(path, path.is_dir()) {
ignore::Match::None => {}
ignore::Match::Ignore(_) => continue 'path,
ignore::Match::Whitelist(_) => break,
}
}
}
walk.overrides(overrides);
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[files]
extend-exclude = ["file.ignore"]
extend-exclude = ["file.ignore", "ignore"]

[default.extend-identifiers]
hello = "goodbye"
1 change: 1 addition & 0 deletions crates/typos-cli/tests/cmd/force-exclude.in/ignore/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
3 changes: 1 addition & 2 deletions crates/typos-cli/tests/cmd/force-exclude.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
bin.name = "typos"
args = "file.ignore --force-exclude"
args = "file.ignore ignore/file parent/ignore/file --force-exclude"
stdin = ""
stdout = ""
stderr = ""
status.code = 0

0 comments on commit f01cfa5

Please sign in to comment.