mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
chore: Run cargo fmt
This commit is contained in:
parent
42e51be1b7
commit
9f198c973d
8 changed files with 86 additions and 29 deletions
|
@ -20,4 +20,3 @@ fn no_correction(b: &mut test::Bencher) {
|
|||
assert_eq!(corrections.correct_str("success"), None);
|
||||
b.iter(|| corrections.correct_str("success"));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,4 +29,3 @@ fn main() {
|
|||
";
|
||||
|
||||
pub const CORPUS: &str = include_str!("../assets/words.csv");
|
||||
|
||||
|
|
|
@ -13,7 +13,13 @@ fn process_empty(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::EMPTY).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -25,7 +31,13 @@ fn process_no_tokens(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::NO_TOKENS).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -37,7 +49,13 @@ fn process_single_token(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::SINGLE_TOKEN).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -49,7 +67,13 @@ fn process_sherlock(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::SHERLOCK).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -61,7 +85,13 @@ fn process_code(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::CODE).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
@ -73,7 +103,13 @@ fn process_corpus(b: &mut test::Bencher) {
|
|||
sample_path.write_str(data::CORPUS).unwrap();
|
||||
|
||||
let corrections = defenestrate::Dictionary::new();
|
||||
b.iter(|| defenestrate::process_file(sample_path.path(), &corrections, defenestrate::report::print_silent));
|
||||
b.iter(|| {
|
||||
defenestrate::process_file(
|
||||
sample_path.path(),
|
||||
&corrections,
|
||||
defenestrate::report::print_silent,
|
||||
)
|
||||
});
|
||||
|
||||
temp.close().unwrap();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ fn tokenize_no_tokens(b: &mut test::Bencher) {
|
|||
|
||||
#[bench]
|
||||
fn tokenize_single_token(b: &mut test::Bencher) {
|
||||
b.iter(|| defenestrate::tokens::Symbol::parse(data::SINGLE_TOKEN.as_bytes()).collect::<Vec<_>>());
|
||||
b.iter(|| {
|
||||
defenestrate::tokens::Symbol::parse(data::SINGLE_TOKEN.as_bytes()).collect::<Vec<_>>()
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
|
@ -11,7 +11,11 @@ pub use crate::dict::*;
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
pub fn process_file(path: &std::path::Path, dictionary: &Dictionary, report: report::Report) -> Result<(), failure::Error> {
|
||||
pub fn process_file(
|
||||
path: &std::path::Path,
|
||||
dictionary: &Dictionary,
|
||||
report: report::Report,
|
||||
) -> Result<(), failure::Error> {
|
||||
let mut buffer = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buffer)?;
|
||||
for (line_idx, line) in grep_searcher::LineIter::new(b'\n', &buffer).enumerate() {
|
||||
|
@ -38,4 +42,3 @@ pub fn process_file(path: &std::path::Path, dictionary: &Dictionary, report: rep
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -4,7 +4,7 @@ extern crate clap;
|
|||
|
||||
use structopt::StructOpt;
|
||||
|
||||
arg_enum!{
|
||||
arg_enum! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
enum Format {
|
||||
Silent,
|
||||
|
@ -37,13 +37,14 @@ struct Options {
|
|||
/// Paths to check
|
||||
path: Vec<std::path::PathBuf>,
|
||||
|
||||
|
||||
#[structopt(long = "format",
|
||||
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
|
||||
default_value = "long")]
|
||||
#[structopt(
|
||||
long = "format",
|
||||
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
|
||||
default_value = "long"
|
||||
)]
|
||||
pub format: Format,
|
||||
|
||||
#[structopt(short="j", long="threads", default_value="0")]
|
||||
#[structopt(short = "j", long = "threads", default_value = "0")]
|
||||
/// The approximate number of threads to use.
|
||||
threads: usize,
|
||||
}
|
||||
|
@ -65,7 +66,10 @@ fn run() -> Result<(), failure::Error> {
|
|||
|
||||
let dictionary = defenestrate::Dictionary::new();
|
||||
|
||||
let first_path = &options.path.get(0).expect("arg parsing enforces at least one");
|
||||
let first_path = &options
|
||||
.path
|
||||
.get(0)
|
||||
.expect("arg parsing enforces at least one");
|
||||
let mut walk = ignore::WalkBuilder::new(first_path);
|
||||
for path in &options.path[1..] {
|
||||
walk.add(path);
|
||||
|
|
|
@ -13,11 +13,17 @@ pub struct Message<'m> {
|
|||
|
||||
pub type Report = fn(msg: Message);
|
||||
|
||||
pub fn print_silent(_: Message) {
|
||||
}
|
||||
pub fn print_silent(_: Message) {}
|
||||
|
||||
pub fn print_brief(msg: Message) {
|
||||
println!("{}:{}:{}: {} -> {}", msg.path.display(), msg.line_num, msg.col_num, msg.word, msg.correction);
|
||||
println!(
|
||||
"{}:{}:{}: {} -> {}",
|
||||
msg.path.display(),
|
||||
msg.line_num,
|
||||
msg.col_num,
|
||||
msg.word,
|
||||
msg.correction
|
||||
);
|
||||
}
|
||||
|
||||
pub fn print_long(msg: Message) {
|
||||
|
@ -28,9 +34,18 @@ pub fn print_long(msg: Message) {
|
|||
let hl: String = itertools::repeat_n("^", msg.word.len()).collect();
|
||||
|
||||
println!("error: `{}` should be `{}`", msg.word, msg.correction);
|
||||
println!(" --> {}:{}:{}", msg.path.display(), msg.line_num, msg.col_num);
|
||||
println!(
|
||||
" --> {}:{}:{}",
|
||||
msg.path.display(),
|
||||
msg.line_num,
|
||||
msg.col_num
|
||||
);
|
||||
println!("{} |", line_indent);
|
||||
println!("{} | {}", msg.line_num, String::from_utf8_lossy(msg.line).trim_end());
|
||||
println!(
|
||||
"{} | {}",
|
||||
msg.line_num,
|
||||
String::from_utf8_lossy(msg.line).trim_end()
|
||||
);
|
||||
println!("{} | {}{}", line_indent, hl_indent, hl);
|
||||
println!("{} |", line_indent);
|
||||
}
|
||||
|
|
|
@ -6,17 +6,16 @@ pub struct Symbol<'t> {
|
|||
|
||||
impl<'t> Symbol<'t> {
|
||||
pub fn new(token: &'t [u8], offset: usize) -> Self {
|
||||
Self {
|
||||
token,
|
||||
offset,
|
||||
}
|
||||
Self { token, offset }
|
||||
}
|
||||
|
||||
pub fn parse<'s>(content: &'s [u8]) -> impl Iterator<Item=Symbol<'s>> {
|
||||
pub fn parse<'s>(content: &'s [u8]) -> impl Iterator<Item = Symbol<'s>> {
|
||||
lazy_static::lazy_static! {
|
||||
static ref SPLIT: regex::bytes::Regex = regex::bytes::Regex::new(r#"\b(\p{Alphabetic}|\d|_)+\b"#).unwrap();
|
||||
}
|
||||
SPLIT.find_iter(content).map(|m| Symbol::new(m.as_bytes(), m.start()))
|
||||
SPLIT
|
||||
.find_iter(content)
|
||||
.map(|m| Symbol::new(m.as_bytes(), m.start()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue