Skip to content

Commit e24c694

Browse files
committed
fix(cli): Respect force-exclude for simple exclude pattersn
Fixes #868
1 parent edfb79f commit e24c694

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

crates/typos-cli/src/bin/typos-cli/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
188188
};
189189

190190
// Note: file_list and args.path are mutually exclusive, enforced by clap
191-
for path in file_list.as_ref().unwrap_or(&args.path) {
191+
'path: for path in file_list.as_ref().unwrap_or(&args.path) {
192192
// Note paths are passed through stdin, `-` is treated like a normal path
193193
let cwd = if path == std::path::Path::new("-") {
194194
if args.file_list.is_some() {
@@ -244,8 +244,14 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
244244
.build()
245245
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
246246
if args.force_exclude {
247-
if let ignore::Match::Ignore(_) = overrides.matched(path, path.is_dir()) {
248-
continue;
247+
let mut ancestors = path.ancestors().collect::<Vec<_>>();
248+
ancestors.reverse();
249+
for path in ancestors {
250+
match overrides.matched(path, path.is_dir()) {
251+
ignore::Match::None => {}
252+
ignore::Match::Ignore(_) => continue 'path,
253+
ignore::Match::Whitelist(_) => break,
254+
}
249255
}
250256
}
251257
walk.overrides(overrides);
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
bin.name = "typos"
22
args = "file.ignore ignore/file parent/ignore/file --force-exclude"
33
stdin = ""
4-
stdout = """
5-
error: `hello` should be `goodbye`
6-
--> ignore/file:1:1
7-
|
8-
1 | hello
9-
| ^^^^^
10-
|
11-
error: `hello` should be `goodbye`
12-
--> parent/ignore/file:1:1
13-
|
14-
1 | hello
15-
| ^^^^^
16-
|
17-
"""
4+
stdout = ""
185
stderr = ""
19-
status.code = 2

0 commit comments

Comments
 (0)