mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
parent
4ce7303fc2
commit
da156e3f23
3 changed files with 27 additions and 0 deletions
|
@ -18,6 +18,7 @@ fn process_empty(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -37,6 +38,7 @@ fn process_no_tokens(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -56,6 +58,7 @@ fn process_single_token(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -75,6 +78,7 @@ fn process_sherlock(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -94,6 +98,7 @@ fn process_code(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -113,6 +118,7 @@ fn process_corpus(b: &mut test::Bencher) {
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,10 +18,14 @@ pub fn process_file(
|
||||||
path: &std::path::Path,
|
path: &std::path::Path,
|
||||||
dictionary: &Dictionary,
|
dictionary: &Dictionary,
|
||||||
ignore_hex: bool,
|
ignore_hex: bool,
|
||||||
|
binary: bool,
|
||||||
report: report::Report,
|
report: report::Report,
|
||||||
) -> Result<(), failure::Error> {
|
) -> Result<(), failure::Error> {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
File::open(path)?.read_to_end(&mut buffer)?;
|
File::open(path)?.read_to_end(&mut buffer)?;
|
||||||
|
if !binary && buffer.find_byte(b'\0').is_some() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
for (line_idx, line) in buffer.lines().enumerate() {
|
for (line_idx, line) in buffer.lines().enumerate() {
|
||||||
let line_num = line_idx + 1;
|
let line_num = line_idx + 1;
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -55,6 +55,12 @@ struct Options {
|
||||||
/// The approximate number of threads to use.
|
/// The approximate number of threads to use.
|
||||||
threads: usize,
|
threads: usize,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""no-binary""#))]
|
||||||
|
/// Search binary files.
|
||||||
|
binary: bool,
|
||||||
|
#[structopt(long, raw(overrides_with = r#""binary""#), raw(hidden = "true"))]
|
||||||
|
no_binary: bool,
|
||||||
|
|
||||||
#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
|
#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
|
||||||
/// Search hidden files and directories.
|
/// Search hidden files and directories.
|
||||||
hidden: bool,
|
hidden: bool,
|
||||||
|
@ -118,6 +124,15 @@ impl Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn binary(&self) -> Option<bool> {
|
||||||
|
match (self.binary, self.no_binary) {
|
||||||
|
(true, false) => Some(true),
|
||||||
|
(false, true) => Some(false),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ignore_hidden(&self) -> Option<bool> {
|
pub fn ignore_hidden(&self) -> Option<bool> {
|
||||||
match (self.hidden, self.no_hidden) {
|
match (self.hidden, self.no_hidden) {
|
||||||
(true, false) => Some(false),
|
(true, false) => Some(false),
|
||||||
|
@ -183,6 +198,7 @@ fn run() -> Result<(), failure::Error> {
|
||||||
|
|
||||||
let dictionary = typos::Dictionary::new();
|
let dictionary = typos::Dictionary::new();
|
||||||
let ignore_hex = options.ignore_hex().unwrap_or(true);
|
let ignore_hex = options.ignore_hex().unwrap_or(true);
|
||||||
|
let binary = options.binary().unwrap_or(false);
|
||||||
|
|
||||||
let first_path = &options
|
let first_path = &options
|
||||||
.path
|
.path
|
||||||
|
@ -207,6 +223,7 @@ fn run() -> Result<(), failure::Error> {
|
||||||
entry.path(),
|
entry.path(),
|
||||||
&dictionary,
|
&dictionary,
|
||||||
ignore_hex,
|
ignore_hex,
|
||||||
|
binary,
|
||||||
options.format.report(),
|
options.format.report(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue