Skip to content

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

fix: break words on hyphens for the `an_a` lint

Alex Ozdemir4b7bedc96e62
diff --git a/harper-core/src/linting/an_a.rs b/harper-core/src/linting/an_a.rs
index f5b39736a..a751126ca 100644
--- a/harper-core/src/linting/an_a.rs
+++ b/harper-core/src/linting/an_a.rs
@@ -15,6 +15,12 @@ impl Linter for AnA {
for (first, second) in document.iter_words().tuple_windows() {
let chars_first = document.get_span_content(first.span);
let chars_second = document.get_span_content(second.span);
+ // Break the second word on hyphens for this lint.
+ // Example: "An ML-based" is an acceptable noun phrase.
+ let chars_second = chars_second
+ .split(|c| !c.is_alphanumeric())
+ .next()
+ .unwrap_or(chars_second);
let is_a_an = match chars_first {
['a'] => Some(true),
@@ -170,6 +176,16 @@ mod tests {
assert_lint_count("Here is a LLM document.", AnA, 1);
}
+ #[test]
+ fn detects_llm_hyphen_as_vowel() {
+ assert_lint_count("Here is a LLM-based system.", AnA, 1);
+ }
+
+ #[test]
+ fn capitalized_fourier() {
+ assert_lint_count("Then, perform a Fourier transform.", AnA, 0);
+ }
+
#[test]
fn once_over() {
assert_lint_count("give this a once-over.", AnA, 0);