Skip to content

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

feat: 'npm' requires 'an', not 'a' (#4146)

Andrew Dunbar164635b1d43b
diff --git a/harper-core/src/indefinite_article.rs b/harper-core/src/indefinite_article.rs
index 969d85bd0..8d04f2623 100644
--- a/harper-core/src/indefinite_article.rs
+++ b/harper-core/src/indefinite_article.rs
@@ -6,11 +6,11 @@ use crate::case::Case::Upper;
use crate::char_ext::CharExt;
use crate::{CaseIterExt, Dialect};
-#[derive(PartialEq)]
+#[derive(Debug, PartialEq)]
pub enum InitialSound {
Vowel,
Consonant,
- Either, // for SQL
+ Either,
}
/// Checks whether a provided word begins with a vowel _sound_. Returns `None` if `word` is empty.
@@ -74,6 +74,11 @@ pub fn starts_with_vowel(word: &[char], dialect: Dialect) -> Option<InitialSound
return Some(InitialSound::Vowel);
}
+ // `npm` is officially an all-lowercase initialism pronounced letter-by-letter
+ if matches!(word, ['n', 'p', 'm']) {
+ return Some(InitialSound::Vowel);
+ }
+
if matches!(word, ['e', 'u', 'l', 'e', ..]) {
return Some(InitialSound::Vowel);
}
@@ -214,3 +219,16 @@ fn is_likely_acronym(word: &[char]) -> bool {
false
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_npm_4139() {
+ assert_eq!(
+ starts_with_vowel(&['n', 'p', 'm'].to_vec(), Dialect::American),
+ Some(InitialSound::Vowel)
+ );
+ }
+}
diff --git a/harper-core/src/linting/an_a.rs b/harper-core/src/linting/an_a.rs
index d82012ca0..541a1499d 100644
--- a/harper-core/src/linting/an_a.rs
+++ b/harper-core/src/linting/an_a.rs
@@ -394,4 +394,21 @@ mod tests {
fn dont_flag_is_80_an_a_3715() {
assert_no_lints("Is 80 an A in Malaysia?", AnA::new(Dialect::American));
}
+
+ #[test]
+ fn dont_flag_an_npm_4139() {
+ assert_no_lints(
+ "Why lib/ or light-base/ alone forces an npm bump",
+ AnA::new(Dialect::American),
+ );
+ }
+
+ #[test]
+ fn correct_a_npm_4139() {
+ assert_suggestion_result(
+ "Why lib/ or light-base/ alone forces a npm bump",
+ AnA::new(Dialect::American),
+ "Why lib/ or light-base/ alone forces an npm bump",
+ );
+ }
}