From edfb79f537bbc371d90eb9ecd5628286a7ce1088 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Nov 2023 11:20:21 -0600 Subject: [PATCH 1/2] test(cli): Reproduce force-exclude bug --- .../tests/cmd/force-exclude.in/_typos.toml | 2 +- .../tests/cmd/force-exclude.in/ignore/file | 1 + .../cmd/force-exclude.in/parent/ignore/file | 1 + crates/typos-cli/tests/cmd/force-exclude.toml | 19 ++++++++++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 crates/typos-cli/tests/cmd/force-exclude.in/ignore/file create mode 100644 crates/typos-cli/tests/cmd/force-exclude.in/parent/ignore/file diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml b/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml index 434f5f6..9d14ee8 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml @@ -1,5 +1,5 @@ [files] -extend-exclude = ["file.ignore"] +extend-exclude = ["file.ignore", "ignore"] [default.extend-identifiers] hello = "goodbye" diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/ignore/file b/crates/typos-cli/tests/cmd/force-exclude.in/ignore/file new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.in/ignore/file @@ -0,0 +1 @@ +hello diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/parent/ignore/file b/crates/typos-cli/tests/cmd/force-exclude.in/parent/ignore/file new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.in/parent/ignore/file @@ -0,0 +1 @@ +hello diff --git a/crates/typos-cli/tests/cmd/force-exclude.toml b/crates/typos-cli/tests/cmd/force-exclude.toml index 863fe82..405c75d 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -1,6 +1,19 @@ bin.name = "typos" -args = "file.ignore --force-exclude" +args = "file.ignore ignore/file parent/ignore/file --force-exclude" stdin = "" -stdout = "" +stdout = """ +error: `hello` should be `goodbye` + --> ignore/file:1:1 + | +1 | hello + | ^^^^^ + | +error: `hello` should be `goodbye` + --> parent/ignore/file:1:1 + | +1 | hello + | ^^^^^ + | +""" stderr = "" -status.code = 0 +status.code = 2 From e24c694258c9d689890692b33f7e1c48f6afd312 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Nov 2023 11:32:44 -0600 Subject: [PATCH 2/2] fix(cli): Respect force-exclude for simple exclude pattersn Fixes #868 --- crates/typos-cli/src/bin/typos-cli/main.rs | 12 +++++++++--- crates/typos-cli/tests/cmd/force-exclude.toml | 16 +--------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index dc8ce6b..629e666 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -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() { @@ -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::>(); + 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); diff --git a/crates/typos-cli/tests/cmd/force-exclude.toml b/crates/typos-cli/tests/cmd/force-exclude.toml index 405c75d..4587740 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -1,19 +1,5 @@ bin.name = "typos" args = "file.ignore ignore/file parent/ignore/file --force-exclude" stdin = "" -stdout = """ -error: `hello` should be `goodbye` - --> ignore/file:1:1 - | -1 | hello - | ^^^^^ - | -error: `hello` should be `goodbye` - --> parent/ignore/file:1:1 - | -1 | hello - | ^^^^^ - | -""" +stdout = "" stderr = "" -status.code = 2