Skip to content

Commit

Permalink
style: Address clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Jan 2, 2021
1 parent e6a4f49 commit 67222e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/typos/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl<'p, 'd> ParserBuilder<'p, 'd> {
pub fn dictionary<'d1>(self, dictionary: &'d1 dyn Dictionary) -> ParserBuilder<'p, 'd1> {
ParserBuilder {
tokenizer: self.tokenizer,
dictionary: dictionary,
dictionary,
}
}

/// Extract typos from the buffer.
pub fn build(&self) -> TyposParser<'p, 'd> {
TyposParser {
tokenizer: self.tokenizer.unwrap_or_else(|| &DEFAULT_TOKENIZER),
tokenizer: self.tokenizer.unwrap_or(&DEFAULT_TOKENIZER),
dictionary: self.dictionary,
}
}
Expand All @@ -49,7 +49,7 @@ impl<'p> Default for ParserBuilder<'p, 'static> {
}

static DEFAULT_TOKENIZER: once_cell::sync::Lazy<tokens::Tokenizer> =
once_cell::sync::Lazy::new(|| tokens::Tokenizer::new());
once_cell::sync::Lazy::new(tokens::Tokenizer::new);

/// Extract typos from the buffer.
#[derive(Clone)]
Expand Down
9 changes: 2 additions & 7 deletions src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,7 @@ impl FileChecker for DiffTypos {

if new_path.is_some() || !content.is_empty() {
let original_path = path.display().to_string();
let fixed_path = new_path
.as_ref()
.map(|p| p.as_path())
.unwrap_or(path)
.display()
.to_string();
let fixed_path = new_path.as_deref().unwrap_or(path).display().to_string();
let original_content: Vec<_> = content
.lines_with_terminator()
.map(|s| String::from_utf8_lossy(s).into_owned())
Expand Down Expand Up @@ -595,7 +590,7 @@ fn extract_fix<'t>(typo: &'t typos::Typo<'t>) -> Option<&'t str> {
}
}

fn is_fixable<'t>(typo: &typos::Typo<'t>) -> bool {
fn is_fixable(typo: &typos::Typo<'_>) -> bool {
extract_fix(typo).is_some()
}

Expand Down
19 changes: 15 additions & 4 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,21 @@ impl<'r> MessageStatus<'r> {

impl<'r> Report for MessageStatus<'r> {
fn report(&self, msg: Message) -> Result<(), std::io::Error> {
self.typos_found
.compare_and_swap(false, msg.is_correction(), atomic::Ordering::Relaxed);
self.errors_found
.compare_and_swap(false, msg.is_error(), atomic::Ordering::Relaxed);
let _ = self.typos_found.compare_exchange(
false,
msg.is_correction(),
atomic::Ordering::Relaxed,
atomic::Ordering::Relaxed,
);
let _ = self
.errors_found
.compare_exchange(
false,
msg.is_error(),
atomic::Ordering::Relaxed,
atomic::Ordering::Relaxed,
)
.unwrap();
self.reporter.report(msg)
}
}
Expand Down

0 comments on commit 67222e9

Please sign in to comment.