Skip to content

Commit f8f8c6e

Browse files
authored
Merge pull request #884 from epage/custom
fix(dict): Mirror original case for custom dict
2 parents 548ac37 + 55d802d commit f8f8c6e

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

crates/typos-cli/src/dict.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,27 +284,30 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
284284
self.inner.correct_ident(ident)
285285
}
286286

287-
fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
288-
if word.case() == typos::tokens::Case::None {
287+
fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
288+
if word_token.case() == typos::tokens::Case::None {
289289
return None;
290290
}
291291

292292
for ignored in &self.ignored_words {
293-
if ignored.is_match(word.token()) {
293+
if ignored.is_match(word_token.token()) {
294294
return Some(Status::Valid);
295295
}
296296
}
297297

298298
// Skip hashing if we can
299299
if !self.words.is_empty() {
300-
let w = UniCase::new(word.token());
300+
let w = UniCase::new(word_token.token());
301301
// HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow`
302-
if let Some(status) = self.words.get(&w).cloned() {
303-
return Some(status);
302+
if let Some(mut corrections) = self.words.get(&w).cloned() {
303+
for s in corrections.corrections_mut() {
304+
case_correct(s, word_token.case())
305+
}
306+
return Some(corrections);
304307
}
305308
}
306309

307-
self.inner.correct_word(word)
310+
self.inner.correct_word(word_token)
308311
}
309312
}
310313

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[default.extend-words]
2+
"trailling" = "trailing"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bin.name = "typos"
2+
args = ""
3+
status.code = 2
4+
stdin = ""
5+
stdout = """
6+
error: `Trailling` should be `Trailing`
7+
--> ./file.txt:1:26
8+
|
9+
1 | public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)
10+
| ^^^^^^^^^
11+
|
12+
"""
13+
stderr = ""

0 commit comments

Comments
 (0)