From b33ced21437431cbfa1beeaea6e6249cf79968b8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 05:08:49 -0500 Subject: [PATCH 1/2] test(cmd): Show binary exclude bug --- crates/typos-cli/tests/cmd/force-exclude.in/binary | 3 +++ crates/typos-cli/tests/cmd/force-exclude.toml | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 crates/typos-cli/tests/cmd/force-exclude.in/binary diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/binary b/crates/typos-cli/tests/cmd/force-exclude.in/binary new file mode 100644 index 0000000..e76a66f --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.in/binary @@ -0,0 +1,3 @@ +%PDF + +hello diff --git a/crates/typos-cli/tests/cmd/force-exclude.toml b/crates/typos-cli/tests/cmd/force-exclude.toml index 4587740..22ecd95 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -1,5 +1,13 @@ bin.name = "typos" -args = "file.ignore ignore/file parent/ignore/file --force-exclude" +args = "file.ignore ignore/file parent/ignore/file binary --force-exclude" stdin = "" -stdout = "" +stdout = """ +error: `hello` should be `goodbye` + --> binary:3:1 + | +3 | hello + | ^^^^^ + | +""" stderr = "" +status.code = 2 From 1fb118d52fad3aa17a30ed436836c2ba221ee7b3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Oct 2024 05:13:27 -0500 Subject: [PATCH 2/2] fix(cli): Respect force-exclude for binary files Fixes #1126 --- crates/typos-cli/src/bin/typos-cli/main.rs | 9 ++++++++- crates/typos-cli/src/file.rs | 9 ++++++--- crates/typos-cli/tests/cmd/force-exclude.toml | 10 +--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index 9dd8773..9e9fe31 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -298,13 +298,20 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult { }; if single_threaded { - typos_cli::file::walk_path(walk.build(), selected_checks, &engine, reporter) + typos_cli::file::walk_path( + walk.build(), + selected_checks, + &engine, + reporter, + args.force_exclude, + ) } else { typos_cli::file::walk_path_parallel( walk.build_parallel(), selected_checks, &engine, reporter, + args.force_exclude, ) } .map_err(|e| { diff --git a/crates/typos-cli/src/file.rs b/crates/typos-cli/src/file.rs index 450510c..4aee397 100644 --- a/crates/typos-cli/src/file.rs +++ b/crates/typos-cli/src/file.rs @@ -669,9 +669,10 @@ pub fn walk_path( checks: &dyn FileChecker, engine: &crate::policy::ConfigEngine<'_>, reporter: &dyn report::Report, + force_exclude: bool, ) -> Result<(), ignore::Error> { for entry in walk { - walk_entry(entry, checks, engine, reporter)?; + walk_entry(entry, checks, engine, reporter, force_exclude)?; } Ok(()) } @@ -681,11 +682,12 @@ pub fn walk_path_parallel( checks: &dyn FileChecker, engine: &crate::policy::ConfigEngine<'_>, reporter: &dyn report::Report, + force_exclude: bool, ) -> Result<(), ignore::Error> { let error: std::sync::Mutex> = std::sync::Mutex::new(Ok(())); walk.run(|| { Box::new(|entry: Result| { - match walk_entry(entry, checks, engine, reporter) { + match walk_entry(entry, checks, engine, reporter, force_exclude) { Ok(()) => ignore::WalkState::Continue, Err(err) => { *error.lock().unwrap() = Err(err); @@ -703,6 +705,7 @@ fn walk_entry( checks: &dyn FileChecker, engine: &crate::policy::ConfigEngine<'_>, reporter: &dyn report::Report, + force_exclude: bool, ) -> Result<(), ignore::Error> { let entry = match entry { Ok(entry) => entry, @@ -722,7 +725,7 @@ fn walk_entry( return Ok(()); } if entry.file_type().map(|t| t.is_file()).unwrap_or(true) { - let explicit = entry.depth() == 0; + let explicit = entry.depth() == 0 && !force_exclude; let (path, lookup_path) = if entry.is_stdin() { let path = std::path::Path::new("-"); let cwd = std::env::current_dir().map_err(|err| { diff --git a/crates/typos-cli/tests/cmd/force-exclude.toml b/crates/typos-cli/tests/cmd/force-exclude.toml index 22ecd95..3057f1d 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -1,13 +1,5 @@ bin.name = "typos" args = "file.ignore ignore/file parent/ignore/file binary --force-exclude" stdin = "" -stdout = """ -error: `hello` should be `goodbye` - --> binary:3:1 - | -3 | hello - | ^^^^^ - | -""" +stdout = "" stderr = "" -status.code = 2