Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: condense file extensions inside parens (#1640)
Andrew Dunbar88244550f829
diff --git a/harper-core/src/document.rs b/harper-core/src/document.rsindex b16c7eb74..a54ca0e19 100644--- a/harper-core/src/document.rs+++ b/harper-core/src/document.rs@@ -575,22 +575,23 @@ impl Document {let mut ext_start = None;loop {- let a = self.get_token_offset(cursor, -2);- let b = &self.tokens[cursor - 1];- let c = &self.tokens[cursor];- let d = self.get_token_offset(cursor, 1);-- let is_ext_chunk = a.is_none_or(|t| t.kind.is_whitespace())- && b.kind.is_period()- && c.kind.is_word()- && c.span.len() <= 3- && d.is_none_or(|t| t.kind.is_whitespace())- && if d.is_none_or(|t| t.kind.is_whitespace()) {- let ext_chars = c.span.get_content(&self.source);+ // left context, dot, extension, right context+ let l = self.get_token_offset(cursor, -2);+ let d = &self.tokens[cursor - 1];+ let x = &self.tokens[cursor];+ let r = self.get_token_offset(cursor, 1);++ let is_ext_chunk = d.kind.is_period()+ && x.kind.is_word()+ && x.span.len() <= 3+ && ((l.is_none_or(|t| t.kind.is_whitespace())+ && r.is_none_or(|t| t.kind.is_whitespace()))+ || (l.is_some_and(|t| t.kind.is_open_round())+ && r.is_some_and(|t| t.kind.is_close_round())))+ && {+ let ext_chars = x.span.get_content(&self.source);ext_chars.iter().all(|c| c.is_ascii_lowercase())|| ext_chars.iter().all(|c| c.is_ascii_uppercase())- } else {- false};if is_ext_chunk {@@ -657,7 +658,7 @@ impl Document {fn condense_contractions(&mut self) {let expr = Self::CONTRACTION_EXPR.with(|v| v.clone());- self.condense_expr(&expr, |_| {});+ self.condense_expr(&expr, |_| {})}}@@ -974,4 +975,15 @@ mod tests {assert!(doc.tokens[4].kind.is_punctuation());assert!(doc.tokens[5].kind.is_word());}++ #[test]+ fn condense_filename_extension_in_parens() {+ let doc = Document::new_plain_english_curated(+ "true for the manual installation when trying to run the executable(.exe) after a manual download",+ );+ assert!(doc.tokens.len() > 23);+ assert!(doc.tokens[21].kind.is_open_round());+ assert!(doc.tokens[22].kind.is_unlintable());+ assert!(doc.tokens[23].kind.is_close_round());+ }}diff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rsindex ca8e08d09..031f70652 100644--- a/harper-core/src/token_kind.rs+++ b/harper-core/src/token_kind.rs@@ -159,6 +159,14 @@ impl TokenKind {matches!(self, TokenKind::Punctuation(Punctuation::CloseSquare))}+ pub fn is_open_round(&self) -> bool {+ matches!(self, TokenKind::Punctuation(Punctuation::OpenRound))+ }++ pub fn is_close_round(&self) -> bool {+ matches!(self, TokenKind::Punctuation(Punctuation::CloseRound))+ }+pub fn is_pipe(&self) -> bool {matches!(self, TokenKind::Punctuation(Punctuation::Pipe))}