Skip to content

Commit

Permalink
fix(parse): Don't skip binary files when explicitly requested
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
epage committed Aug 1, 2019
1 parent 6142941 commit 750005e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions benches/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
3 changes: 2 additions & 1 deletion src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, failure::Error> {
let mut typos_found = false;
Expand All @@ -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: (),
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@ fn run() -> Result<i32, failure::Error> {
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;
}
}
Expand Down

0 comments on commit 750005e

Please sign in to comment.