Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: GOP party → GOP / Grand Old Party (#3232)
Andrew Dunbarb2794f44a277
diff --git a/harper-core/src/char_string.rs b/harper-core/src/char_string.rsindex 72bebe345..3a58d7f70 100644--- a/harper-core/src/char_string.rs+++ b/harper-core/src/char_string.rs@@ -1,5 +1,6 @@use crate::char_ext::CharExt;use std::borrow::Cow;+use std::iter::Iterator;use smallvec::SmallVec;@@ -101,6 +102,15 @@ impl CharStringExt for [char] {}fn eq_str(&self, other: &str) -> bool {+ // Assert that the right-hand side is all-lowercase as required+ debug_assert!(+ other+ .chars()+ .all(|c| c.is_ascii_lowercase() || !c.is_ascii_alphabetic()),+ "eq_str requires right-hand side to be lowercase ASCII, but got: {:?}",+ other+ );+let mut chit = self.iter();let mut strit = other.chars();@@ -119,6 +129,15 @@ impl CharStringExt for [char] {}fn eq_ch(&self, other: &[char]) -> bool {+ // Assert that the right-hand side is all-lowercase as required+ debug_assert!(+ other+ .iter()+ .all(|c| c.is_ascii_lowercase() || !c.is_ascii_alphabetic()),+ "eq_ch requires right-hand side to be lowercase ASCII, but got: {:?}",+ other+ );+self.len() == other.len()&& self.iter()@@ -254,4 +273,16 @@ mod tests {fn differs_only_by_length_2() {assert!(!['c'].eq_str("cc"));}++ #[test]+ #[should_panic]+ fn right_side_must_be_all_lowercase_str() {+ assert!(['c'].eq_str("C"))+ }++ #[test]+ #[should_panic]+ fn right_side_must_be_all_lowercase_ch() {+ assert!(['c'].eq_ch(&['C']))+ }}diff --git a/harper-core/src/linting/redundant_acronyms.rs b/harper-core/src/linting/redundant_acronyms.rsindex f53875940..77059986e 100644--- a/harper-core/src/linting/redundant_acronyms.rs+++ b/harper-core/src/linting/redundant_acronyms.rs@@ -24,6 +24,7 @@ const ACRONYMS: &[(&str, &[&str], &str, Flag)] = &["machine",None,),+ ("GOP", &["Grand Old"], "Party", None),("GUI", &["graphical user"], "interface", None),("LCD", &["liquid crystal"], "display", None),("LLM", &["large language"], "model", None),@@ -77,7 +78,7 @@ impl ExprLinter for RedundantAcronyms {let last_word_chars = last_word_span.get_content(src);let acronym_str = toks.first()?.get_str(src);- let (_, middle_words, _, flag) = ACRONYMS+ let (_, middle_words, last_word, flag) = ACRONYMS.iter().find(|(a, _, _, _)| (*a).eq_ignore_ascii_case(&acronym_str))?;@@ -104,13 +105,13 @@ impl ExprLinter for RedundantAcronyms {format!("{acronym_str}{plural_ending}").chars().collect(),)).chain(middle_words.iter().map(|mw| {- let middle_words = if is_all_caps {- mw.to_ascii_uppercase()+ let (middle_words, last_word) = if is_all_caps {+ (mw.to_ascii_uppercase(), last_word.to_ascii_uppercase())} else {- mw.to_string()+ (mw.to_string(), last_word.to_string())};Suggestion::ReplaceWith(- format!("{middle_words} {}", last_word_span.get_content_string(src))+ format!("{middle_words} {}{plural_ending}", last_word).chars().collect(),)@@ -118,12 +119,12 @@ impl ExprLinter for RedundantAcronyms {.collect();Some(Lint {- span: toks.span()?,- lint_kind: LintKind::Redundancy,- suggestions,- message: "The acronym's last letter already stands for the last word. Use just the acronym or the full phrase.".to_string(),- ..Default::default()- })+ span: toks.span()?,+ lint_kind: LintKind::Redundancy,+ suggestions,+ message: "The acronym's last letter already stands for the last word. Use just the acronym or the full phrase.".to_string(),+ ..Default::default()+ })}fn description(&self) -> &str {@@ -376,6 +377,19 @@ mod tests {);}+ #[test]+ fn correct_gop_party() {+ assert_good_and_bad_suggestions(+ "If it wasnt for bribery and blackmail there wouldnt be a GOP party",+ RedundantAcronyms::default(),+ &[+ "If it wasnt for bribery and blackmail there wouldnt be a Grand Old Party",+ "If it wasnt for bribery and blackmail there wouldnt be a GOP",+ ],+ &[],+ );+ }+#[test]fn correct_llm_model() {assert_good_and_bad_suggestions(