mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-28 20:11:05 -05:00
Merge pull request #884 from epage/custom
fix(dict): Mirror original case for custom dict
This commit is contained in:
commit
f8f8c6edf1
4 changed files with 26 additions and 7 deletions
|
@ -284,27 +284,30 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
|
|||
self.inner.correct_ident(ident)
|
||||
}
|
||||
|
||||
fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
|
||||
if word.case() == typos::tokens::Case::None {
|
||||
fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
|
||||
if word_token.case() == typos::tokens::Case::None {
|
||||
return None;
|
||||
}
|
||||
|
||||
for ignored in &self.ignored_words {
|
||||
if ignored.is_match(word.token()) {
|
||||
if ignored.is_match(word_token.token()) {
|
||||
return Some(Status::Valid);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip hashing if we can
|
||||
if !self.words.is_empty() {
|
||||
let w = UniCase::new(word.token());
|
||||
let w = UniCase::new(word_token.token());
|
||||
// HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow`
|
||||
if let Some(status) = self.words.get(&w).cloned() {
|
||||
return Some(status);
|
||||
if let Some(mut corrections) = self.words.get(&w).cloned() {
|
||||
for s in corrections.corrections_mut() {
|
||||
case_correct(s, word_token.case())
|
||||
}
|
||||
return Some(corrections);
|
||||
}
|
||||
}
|
||||
|
||||
self.inner.correct_word(word)
|
||||
self.inner.correct_word(word_token)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
[default.extend-words]
|
||||
"trailling" = "trailing"
|
1
crates/typos-cli/tests/cmd/extend-words-case.in/file.txt
Normal file
1
crates/typos-cli/tests/cmd/extend-words-case.in/file.txt
Normal file
|
@ -0,0 +1 @@
|
|||
public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)
|
13
crates/typos-cli/tests/cmd/extend-words-case.toml
Normal file
13
crates/typos-cli/tests/cmd/extend-words-case.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
bin.name = "typos"
|
||||
args = ""
|
||||
status.code = 2
|
||||
stdin = ""
|
||||
stdout = """
|
||||
error: `Trailling` should be `Trailing`
|
||||
--> ./file.txt:1:26
|
||||
|
|
||||
1 | public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
"""
|
||||
stderr = ""
|
Loading…
Reference in a new issue