Skip to content

Commit

Permalink
Merge pull request #520 from Automattic/repeated-and
Browse files Browse the repository at this point in the history
fix(core): `RepeatedWords` now detects repeated `and` tokens
  • Loading branch information
elijah-potter authored Jan 28, 2025
2 parents 4f09bc4 + 38b1883 commit e77086b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions harper-core/src/linting/repeated_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ pub struct RepeatedWords {
impl RepeatedWords {
pub fn new() -> Self {
Self {
special_cases: vec![smallvec!['i', 's'], smallvec!['a']],
special_cases: vec![
smallvec!['i', 's'],
smallvec!['a'],
smallvec!['a', 'n', 'd'],
],
}
}

fn is_special_case(&self, chars: &[char]) -> bool {
self.special_cases.iter().any(|v| v.as_slice() == chars)
let lower = chars.to_lower();

self.special_cases
.iter()
.any(|v| v.as_slice() == lower.as_slice())
}
}

Expand Down Expand Up @@ -113,4 +121,13 @@ mod tests {
"This is a test",
);
}

#[test]
fn double_and() {
assert_suggestion_result(
"And and this is also a test",
RepeatedWords::default(),
"And this is also a test",
);
}
}

0 comments on commit e77086b

Please sign in to comment.