Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
Treat semicolons as chunk separators (#3426)
Muhammad Azmi Farih1b94dcedf1ad
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex 2aad344d1..c1157b4dc 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -825,7 +825,9 @@ impl LintGroup {insert_struct_rule!(WordPressDotcom, true);insert_expr_rule_with_dict!(WorthToDo, true);insert_expr_rule!(WouldNeverHave, true);- insert_expr_rule!(WrongApostrophe, true);+ // Uses Sentence rather than Chunk+ out.add("WrongApostrophe", WrongApostrophe::default());+ out.config.set_rule_enabled("WrongApostrophe", true);// Uses Sentence rather than Chunkout.add("AspireTo", AspireTo::default());diff --git a/harper-core/src/linting/wrong_apostrophe.rs b/harper-core/src/linting/wrong_apostrophe.rsindex a62b6b361..dcaf0b4dd 100644--- a/harper-core/src/linting/wrong_apostrophe.rs+++ b/harper-core/src/linting/wrong_apostrophe.rs@@ -1,7 +1,7 @@use crate::{Token, TokenStringExt,expr::{Expr, FirstMatchOf, SequenceExpr},- linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Chunk},+ linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Sentence},};const CONTRACTION_AND_POSSESSIVE_ENDINGS: [&str; 7] = ["d", "ll", "m", "re", "s", "t", "ve"];@@ -27,7 +27,7 @@ impl Default for WrongApostrophe {}impl ExprLinter for WrongApostrophe {- type Unit = Chunk;+ type Unit = Sentence;fn expr(&self) -> &dyn Expr {&self.exprdiff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rsindex a5b0f7e4d..cb4470e14 100644--- a/harper-core/src/token_kind.rs+++ b/harper-core/src/token_kind.rs@@ -320,7 +320,10 @@ impl TokenKind {TokenKind::Punctuation(punct) => {matches!(punct,- Punctuation::Comma | Punctuation::Quote { .. } | Punctuation::Colon+ Punctuation::Comma+ | Punctuation::Semicolon+ | Punctuation::Quote { .. }+ | Punctuation::Colon)}_ => false,diff --git a/harper-core/src/token_string_ext.rs b/harper-core/src/token_string_ext.rsindex a5585a250..6148cf677 100644--- a/harper-core/src/token_string_ext.rs+++ b/harper-core/src/token_string_ext.rs@@ -302,3 +302,28 @@ impl TokenStringExt for [Token] {self}}++#[cfg(test)]+mod tests {+ use crate::{Document, TokenStringExt};++ fn chunk_strings(source: &str) -> Vec<String> {+ let source_chars = source.chars().collect::<Vec<_>>();+ let document = Document::new_markdown_default_curated(source);++ document+ .iter_chunks()+ .map(|chunk| chunk.span().unwrap().get_content_string(&source_chars))+ .collect()+ }++ #[test]+ fn comma_separates_chunks() {+ assert_eq!(chunk_strings("foo bar, baz"), vec!["foo bar,", " baz"]);+ }++ #[test]+ fn semicolon_separates_chunks() {+ assert_eq!(chunk_strings("foo bar; baz"), vec!["foo bar;", " baz"]);+ }+}