Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix: correct a/an before MP3 (#1608)

Andrew Dunbar20ec41bb4101
diff --git a/harper-core/src/linting/an_a.rs b/harper-core/src/linting/an_a.rs
index eaf01c297..87d6787cd 100644
--- a/harper-core/src/linting/an_a.rs
+++ b/harper-core/src/linting/an_a.rs
@@ -96,7 +96,7 @@ fn to_lower_word(word: &[char]) -> Cow<'_, [char]> {
/// Matches with 99.71% and 99.77% of vowels and non-vowels in the
/// Carnegie-Mellon University word -> pronunciation dataset.
fn starts_with_vowel(word: &[char]) -> bool {
- let is_likely_initialism = word.iter().all(|c| c.is_uppercase());
+ let is_likely_initialism = word.iter().all(|c| !c.is_alphabetic() || c.is_uppercase());
if is_likely_initialism && !word.is_empty() {
return matches!(
@@ -279,4 +279,14 @@ mod tests {
fn allow_issue_751() {
assert_lint_count("He got a 52% approval rating.", AnA, 0);
}
+
+ #[test]
+ fn allow_an_mp_and_an_mp3() {
+ assert_lint_count("an MP and an MP3?", AnA, 0);
+ }
+
+ #[test]
+ fn disallow_a_mp_and_a_mp3() {
+ assert_lint_count("a MP and a MP3?", AnA, 2);
+ }
}