diff --git a/benches/file.rs b/benches/file.rs index 0783e865e..27a7c31d8 100644 --- a/benches/file.rs +++ b/benches/file.rs @@ -15,7 +15,7 @@ fn process_empty(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } @@ -29,7 +29,7 @@ fn process_no_tokens(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } @@ -43,7 +43,7 @@ fn process_single_token(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } @@ -57,7 +57,7 @@ fn process_sherlock(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } @@ -71,7 +71,7 @@ fn process_code(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } @@ -85,7 +85,7 @@ fn process_corpus(b: &mut test::Bencher) { let corrections = typos::BuiltIn::new(); let parser = typos::tokens::Parser::new(); let checks = typos::checks::CheckSettings::new().build(&corrections, &parser); - b.iter(|| checks.check_file(sample_path.path(), typos::report::print_silent)); + b.iter(|| checks.check_file(sample_path.path(), true, typos::report::print_silent)); temp.close().unwrap(); } diff --git a/src/checks.rs b/src/checks.rs index 308d724c8..4c8b475d4 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -111,6 +111,7 @@ impl<'d, 'p> Checks<'d, 'p> { pub fn check_file( &self, path: &std::path::Path, + explicit: bool, report: report::Report, ) -> Result { let mut typos_found = false; @@ -121,7 +122,7 @@ impl<'d, 'p> Checks<'d, 'p> { let mut buffer = Vec::new(); File::open(path)?.read_to_end(&mut buffer)?; - if !self.binary && buffer.find_byte(b'\0').is_some() { + if !explicit && !self.binary && buffer.find_byte(b'\0').is_some() { let msg = report::BinaryFile { path, non_exhaustive: (), diff --git a/src/main.rs b/src/main.rs index 8673f7efe..456a054e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -290,10 +290,11 @@ fn run() -> Result { for entry in walk.build() { let entry = entry?; if entry.file_type().map(|t| t.is_file()).unwrap_or(true) { + let explicit = entry.depth() == 0; if checks.check_filename(entry.path(), options.format.report())? { typos_found = true; } - if checks.check_file(entry.path(), options.format.report())? { + if checks.check_file(entry.path(), explicit, options.format.report())? { typos_found = true; } }