Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): stop SplitWords treating short non-anchor words as split anchors (#4212)
Vijay Misalf41bec48c025
diff --git a/harper-comments/tests/language_support.rs b/harper-comments/tests/language_support.rsindex ce8e39f44..7d46c729c 100644--- a/harper-comments/tests/language_support.rs+++ b/harper-comments/tests/language_support.rs@@ -82,7 +82,7 @@ create_test!(ignore_comments.ps1, 1);// Zig tests - covering //, ///, and //! commentscreate_test!(clean.zig, 0);-create_test!(dirty.zig, 5);+create_test!(dirty.zig, 4);// These are to make sure nothing crashes.create_test!(empty.js, 0);diff --git a/harper-core/src/linting/split_words.rs b/harper-core/src/linting/split_words.rsindex e1facf359..4ee9e0b81 100644--- a/harper-core/src/linting/split_words.rs+++ b/harper-core/src/linting/split_words.rs@@ -117,7 +117,7 @@ impl ExprLinter for SplitWords {continue;}- if is_anchor_split(&cand_meta, candidate) || is_anchor_split(&rem_meta, remainder) {+ if is_anchor_split(&cand_meta) || is_anchor_split(&rem_meta) {has_anchor_split = true;}@@ -169,13 +169,14 @@ impl ExprLinter for SplitWords {}}-fn is_anchor_split(meta: &crate::DictWordMetadata, word: &[char]) -> bool {+/// Only tagged function words anchor splits; short non-function words like+/// "ha" must not block spelling corrections such as `havent` → `haven't`.+fn is_anchor_split(meta: &crate::DictWordMetadata) -> bool {meta.preposition|| meta.is_determiner()|| meta.is_conjunction()|| meta.is_pronoun()|| meta.is_adverb()- || word.len() <= 2}fn should_defer_to_spellcheck(@@ -292,6 +293,23 @@ mod tests {assert_no_lints("I love this extention!", SplitWords::default());}+ /// Regression: `havent` should defer to SpellCheck's `haven't` suggestion,+ /// not split into `ha vent` (issue #4130).+ #[test]+ fn issue_4130_defers_havent_to_spellcheck() {+ assert_no_lints("They havent reviewed it yet.", SplitWords::default());+ }++ /// Genuine short anchors like `at` should still produce splits.+ #[test]+ fn issue_4130_does_not_regress_real_short_anchors() {+ assert_suggestion_result(+ "don't seem to support symbolic links atall.",+ SplitWords::default(),+ "don't seem to support symbolic links at all.",+ );+ }+#[test]fn corrects_doesthe() {assert_suggestion_result("doesthe", SplitWords::default(), "does the");diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.ymlindex 3cccb6378..4ee795ba7 100644--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml@@ -1070,15 +1070,6 @@ Suggest:-Lint: Typo (31 priority)-Message: |- 668 | “Sure, it’s an arm, yer honour!” (He pronounced it “arrum.”)- | ^~~~~ `arrum` should probably be written as `arr um`.-Suggest:- - Replace with: “arr um”---Lint: Regionalism (127 priority)Message: |681 | thought Alice. “I wonder what they’ll do next! As for pulling me out of the@@ -3212,16 +3203,6 @@ Suggest:-Lint: Typo (31 priority)-Message: |- 2490 | > beautiful Soup? Beau—ootiful Soo—oop! Beau—ootiful Soo—oop! Soo—oop of the- 2491 | > e—e—evening, Beautiful, beauti—FUL SOUP!”- | ^~~~~~ `beauti` should probably be written as `beau ti`.-Suggest:- - Replace with: “beau ti”---Lint: Spelling (63 priority)Message: |2490 | > beautiful Soup? Beau—ootiful Soo—oop! Beau—ootiful Soo—oop! Soo—oop of thediff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.ymlindex 385affd54..129ae7e70 100644--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml@@ -3475,16 +3475,6 @@ Suggest:-Lint: Typo (31 priority)-Message: |- 2319 | That was nineteen-seventeen. By the next year I had a few beaux myself, and I- | ^~~~~ `beaux` should probably be written as `be aux`.- 2320 | began to play in tournaments, so I didn’t see Daisy very often. She went with a-Suggest:- - Replace with: “be aux”---Lint: Spelling (63 priority)Message: |2329 | By the next autumn she was gay again, gay as ever. She had a début after the@@ -3784,16 +3774,6 @@ Suggest:-Lint: Typo (31 priority)-Message: |- 2607 | Clay’s “Economics,” starting at the Finnish tread that shook the kitchen floor,- 2608 | and peering toward the bleared windows from time to time as if a series of- | ^~~~~~~ `bleared` should probably be written as `bl eared`.-Suggest:- - Replace with: “bl eared”---Lint: Style (31 priority)Message: |2629 | The exhilarating ripple of her voice was a wild tonic in the rain. I had to