forked from crate-ci/typos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching `valid-*` to just `*` where you map typo to correction, with support for always-valid and never-valid. Fixes #9
- Loading branch information
Ed Page
committed
Oct 28, 2020
1 parent
79d10d6
commit 527b983
Showing
11 changed files
with
352 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
use std::borrow::Cow; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, serde::Serialize, derive_more::From)] | ||
#[serde(rename_all = "snake_case")] | ||
#[serde(untagged)] | ||
pub enum Status<'c> { | ||
Valid, | ||
Invalid, | ||
Corrections(Vec<Cow<'c, str>>), | ||
} | ||
|
||
impl<'c> Status<'c> { | ||
pub fn is_invalid(&self) -> bool { | ||
matches!(self, Status::Invalid) | ||
} | ||
pub fn is_valid(&self) -> bool { | ||
matches!(self, Status::Valid) | ||
} | ||
pub fn is_correction(&self) -> bool { | ||
matches!(self, Status::Corrections(_)) | ||
} | ||
|
||
pub fn corrections_mut(&mut self) -> impl Iterator<Item = &mut Cow<'c, str>> { | ||
match self { | ||
Status::Corrections(corrections) => itertools::Either::Left(corrections.iter_mut()), | ||
_ => itertools::Either::Right([].iter_mut()), | ||
} | ||
} | ||
|
||
pub fn borrow(&self) -> Status<'_> { | ||
match self { | ||
Status::Corrections(corrections) => { | ||
let corrections = corrections | ||
.iter() | ||
.map(|c| Cow::Borrowed(c.as_ref())) | ||
.collect(); | ||
Status::Corrections(corrections) | ||
} | ||
_ => self.clone(), | ||
} | ||
} | ||
} | ||
|
||
pub trait Dictionary: Send + Sync { | ||
fn correct_ident<'s, 'w>(&'s self, _ident: crate::tokens::Identifier<'w>) -> Vec<Cow<'s, str>>; | ||
fn correct_ident<'s, 'w>(&'s self, _ident: crate::tokens::Identifier<'w>) | ||
-> Option<Status<'s>>; | ||
|
||
fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Vec<Cow<'s, str>>; | ||
fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Option<Status<'s>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.