mirror of
https://github.com/crate-ci/typos.git
synced 2026-10-18 09:55:12 +02:00
chore: Run cargo fmt
This commit is contained in:
+5
-2
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -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);
|
||||
|
||||
+20
-5
@@ -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);
|
||||
}
|
||||
|
||||
+5
-6
@@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user