Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Respect force-exclude for binary files #1131

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
9 changes: 6 additions & 3 deletions crates/typos-cli/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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<Result<(), ignore::Error>> = std::sync::Mutex::new(Ok(()));
walk.run(|| {
Box::new(|entry: Result<ignore::DirEntry, ignore::Error>| {
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);
Expand All @@ -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,
Expand All @@ -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| {
Expand Down
3 changes: 3 additions & 0 deletions crates/typos-cli/tests/cmd/force-exclude.in/binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%PDF

hello
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/force-exclude.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 = ""
stderr = ""
Loading