mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
feat: Give control over verifying file content
This commit is contained in:
parent
ec307dffdd
commit
95c0aea484
3 changed files with 63 additions and 33 deletions
|
@ -19,6 +19,7 @@ fn process_empty(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -40,6 +41,7 @@ fn process_no_tokens(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -61,6 +63,7 @@ fn process_single_token(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -82,6 +85,7 @@ fn process_sherlock(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -103,6 +107,7 @@ fn process_code(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -124,6 +129,7 @@ fn process_corpus(b: &mut test::Bencher) {
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub fn process_file(
|
||||||
path: &std::path::Path,
|
path: &std::path::Path,
|
||||||
dictionary: &Dictionary,
|
dictionary: &Dictionary,
|
||||||
check_filenames: bool,
|
check_filenames: bool,
|
||||||
|
check_files: bool,
|
||||||
ignore_hex: bool,
|
ignore_hex: bool,
|
||||||
binary: bool,
|
binary: bool,
|
||||||
report: report::Report,
|
report: report::Report,
|
||||||
|
@ -52,6 +53,7 @@ pub fn process_file(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if check_files {
|
||||||
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() {
|
if !binary && buffer.find_byte(b'\0').is_some() {
|
||||||
|
@ -99,6 +101,7 @@ pub fn process_file(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -48,6 +48,16 @@ struct Options {
|
||||||
)]
|
)]
|
||||||
check_filenames: bool,
|
check_filenames: bool,
|
||||||
|
|
||||||
|
#[structopt(long, raw(overrides_with = r#""check-files""#))]
|
||||||
|
/// Skip verifying spelling in filess.
|
||||||
|
no_check_files: bool,
|
||||||
|
#[structopt(
|
||||||
|
long,
|
||||||
|
raw(overrides_with = r#""no-check-files""#),
|
||||||
|
raw(hidden = "true")
|
||||||
|
)]
|
||||||
|
check_files: bool,
|
||||||
|
|
||||||
#[structopt(long, raw(overrides_with = r#""hex""#))]
|
#[structopt(long, raw(overrides_with = r#""hex""#))]
|
||||||
/// Don't try to detect that an identifier looks like hex
|
/// Don't try to detect that an identifier looks like hex
|
||||||
no_hex: bool,
|
no_hex: bool,
|
||||||
|
@ -125,6 +135,15 @@ impl Options {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_files(&self) -> Option<bool> {
|
||||||
|
match (self.check_files, self.no_check_files) {
|
||||||
|
(true, false) => Some(true),
|
||||||
|
(false, true) => Some(false),
|
||||||
|
(false, false) => None,
|
||||||
|
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_filenames(&self) -> Option<bool> {
|
pub fn check_filenames(&self) -> Option<bool> {
|
||||||
match (self.check_filenames, self.no_check_filenames) {
|
match (self.check_filenames, self.no_check_filenames) {
|
||||||
(true, false) => Some(true),
|
(true, false) => Some(true),
|
||||||
|
@ -217,6 +236,7 @@ fn run() -> Result<(), failure::Error> {
|
||||||
|
|
||||||
let dictionary = typos::Dictionary::new();
|
let dictionary = typos::Dictionary::new();
|
||||||
let check_filenames = options.check_filenames().unwrap_or(true);
|
let check_filenames = options.check_filenames().unwrap_or(true);
|
||||||
|
let check_files = options.check_files().unwrap_or(true);
|
||||||
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 binary = options.binary().unwrap_or(false);
|
||||||
|
|
||||||
|
@ -243,6 +263,7 @@ fn run() -> Result<(), failure::Error> {
|
||||||
entry.path(),
|
entry.path(),
|
||||||
&dictionary,
|
&dictionary,
|
||||||
check_filenames,
|
check_filenames,
|
||||||
|
check_files,
|
||||||
ignore_hex,
|
ignore_hex,
|
||||||
binary,
|
binary,
|
||||||
options.format.report(),
|
options.format.report(),
|
||||||
|
|
Loading…
Reference in a new issue