Repository navigation
fix(core): stop SplitWords treating short non-anchor words as split anchors - #4212
Merged
hippietrail merged 5 commits intoSep 26, 2026
Merged
Conversation
…nchors
SplitWords' should_defer_to_spellcheck() is meant to prefer a strong
single-word spelling correction over a compound-word split, except when
the split includes a genuine function-word "anchor" (preposition,
determiner, conjunction, pronoun, or adverb) such as "at" in "atall".
is_anchor_split() fell back to treating *any* word of length <= 2 as
an anchor, regardless of its part of speech. That's too broad: it also
matches short interjections/fragments that happen to be in the
dictionary, like "ha" and "um". As a result, "havent" (missing
apostrophe) was split into "ha" + "vent" ("ha vent") instead of
deferring to SpellCheck's correct "haven't" suggestion, even in a
nounish context like "they havent reviewed it yet." (Automattic#4130).
Fix: is_anchor_split() now only checks tagged part-of-speech metadata
(preposition/determiner/conjunction/pronoun/adverb) and drops the
length-based fallback. Real short anchors like "at"/"of" are still
covered because they're already tagged as prepositions in the curated
dictionary, so `atall` -> `at all` is unaffected (see
issue_4130_does_not_regress_real_short_anchors test).
Regenerated the two corpus snapshots this also touches (Alice's
Adventures in Wonderland, The Great Gatsby): both changes remove other
nonsensical SplitWords suggestions of the same shape ("beaux" -> "be
aux", "bleared" -> "bl eared", "arrum" -> "arr um", "beauti" -> "beau
ti"), each of which already had a better SpellCheck/Style suggestion
sitting right below it.
Fixes Automattic#4130
AI assistance: implemented and tested by an AI coding agent (Claude
Sonnet 5) operating autonomously from a GitHub issue, with human
review before submission.
Traced the count change from 5 -> 4 by diffing the lint output with and
without the split_words.rs fix from the previous commit. The words in
dirty.zig are "mispelling" and "speling" (and "teh" via a different
rule). With the old is_anchor_split() fallback, "mispelling" (span
80-90) produced two overlapping lints on the same span:
- Spelling::SpellCheck -> "misspelling" (correct)
- Typo::SplitWords -> "mi spelling" (bogus: "mispelling" splits into
"mi" + "spelling", and "mi" is a 2-letter dictionary word that was
wrongly treated as an anchor purely by length)
That's the same bug class as the reported "havent" -> "ha vent" issue,
just triggered by a different word already present in this existing
fixture. The fix in the previous commit correctly stops SplitWords
from firing here too, so the fixture now produces 4 lints instead of 5
(the bogus "mi spelling" suggestion is gone; the correct "misspelling"
suggestion remains).
AI assistance: implemented and tested by an AI coding agent (Claude
Sonnet 5) operating autonomously, with human review before submission.
Member
|
Closing for violating the agent policy. |
Member
|
I'm reopening this PR since the bit of the agent policy it violated was added after this PR was submitted. |
elijah-potter
enabled auto-merge
September 24, 2026 21:25
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Sep 24, 2026
hippietrail
enabled auto-merge
September 25, 2026 02:22
jvoisin
pushed a commit
to jvoisin/harper
that referenced
this pull request
Oct 17, 2026
…nchors (Automattic#4212) * fix(core): stop SplitWords treating short non-anchor words as split anchors SplitWords' should_defer_to_spellcheck() is meant to prefer a strong single-word spelling correction over a compound-word split, except when the split includes a genuine function-word "anchor" (preposition, determiner, conjunction, pronoun, or adverb) such as "at" in "atall". is_anchor_split() fell back to treating *any* word of length <= 2 as an anchor, regardless of its part of speech. That's too broad: it also matches short interjections/fragments that happen to be in the dictionary, like "ha" and "um". As a result, "havent" (missing apostrophe) was split into "ha" + "vent" ("ha vent") instead of deferring to SpellCheck's correct "haven't" suggestion, even in a nounish context like "they havent reviewed it yet." (Automattic#4130). Fix: is_anchor_split() now only checks tagged part-of-speech metadata (preposition/determiner/conjunction/pronoun/adverb) and drops the length-based fallback. Real short anchors like "at"/"of" are still covered because they're already tagged as prepositions in the curated dictionary, so `atall` -> `at all` is unaffected (see issue_4130_does_not_regress_real_short_anchors test). Regenerated the two corpus snapshots this also touches (Alice's Adventures in Wonderland, The Great Gatsby): both changes remove other nonsensical SplitWords suggestions of the same shape ("beaux" -> "be aux", "bleared" -> "bl eared", "arrum" -> "arr um", "beauti" -> "beau ti"), each of which already had a better SpellCheck/Style suggestion sitting right below it. Fixes Automattic#4130 AI assistance: implemented and tested by an AI coding agent (Claude Sonnet 5) operating autonomously from a GitHub issue, with human review before submission. * fix(core): update dirty.zig fixture count for the SplitWords fix Traced the count change from 5 -> 4 by diffing the lint output with and without the split_words.rs fix from the previous commit. The words in dirty.zig are "mispelling" and "speling" (and "teh" via a different rule). With the old is_anchor_split() fallback, "mispelling" (span 80-90) produced two overlapping lints on the same span: - Spelling::SpellCheck -> "misspelling" (correct) - Typo::SplitWords -> "mi spelling" (bogus: "mispelling" splits into "mi" + "spelling", and "mi" is a 2-letter dictionary word that was wrongly treated as an anchor purely by length) That's the same bug class as the reported "havent" -> "ha vent" issue, just triggered by a different word already present in this existing fixture. The fix in the previous commit correctly stops SplitWords from firing here too, so the fixture now produces 4 lints instead of 5 (the bogus "mi spelling" suggestion is gone; the correct "misspelling" suggestion remains). AI assistance: implemented and tested by an AI coding agent (Claude Sonnet 5) operating autonomously, with human review before submission. * fix(core): shorten comments --------- Co-authored-by: vjymisal0 <vijay.looprai@gmail.com> Co-authored-by: Elijah Potter <me@elijahpotter.dev> Co-authored-by: Andrew Dunbar <hippytrail@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Fixes #4130
Description
SplitWords'should_defer_to_spellcheck()is meant to prefer a strong single-word spellingcorrection (from
SpellCheck) over a compound-word split, unless the split includes a genuinefunction-word "anchor" (a preposition, determiner, conjunction, pronoun, or adverb) — e.g.
atin
atall->at all.is_anchor_split()fell back to treating any word of length <= 2 as an anchor, regardless ofits part of speech. That's too broad: it also matches short interjections/fragments that happen to
be in the dictionary, like
haandum. As a result:havent(missing apostrophe) was split intoha+vent("ha vent") instead of deferring toSpellCheck's correcthaven'tsuggestion, even in a nounish context like"they havent reviewed it yet."— this is the reported bug.The fix removes the length-based fallback from
is_anchor_split(), so it now only checks taggedpart-of-speech metadata (preposition/determiner/conjunction/pronoun/adverb). Real short anchors
like
at/ofare unaffected because they're already tagged as prepositions in the curateddictionary (
atall->at allstill works, covered byissue_4130_does_not_regress_real_short_anchors).Running the full corpus snapshot tests (
Alice's Adventures in Wonderland,The Great Gatsby)surfaced two more instances of the exact same false-positive shape, which are now fixed as a
side effect and included in the regenerated snapshots:
beaux->be aux(should defer to the existingSpellingsuggestion)bleared->bl eared(should defer to the existingStylesuggestion)arrum->arr umbeauti->beau tiIn every case,
SplitWordswas producing a nonsensical suggestion that overlapped with (and, dueto priority, was shown instead of) an existing, correct
SpellCheck/other suggestion. No newsnapshot regressions were introduced — the diff only ever removes one of two lints on a span,
never changes the winning one.
Demo
CLI before the fix:
CLI after the fix:
How Has This Been Tested?
harper-core/src/linting/split_words.rs:issue_4130_defers_havent_to_spellcheck— RED before the fix (assertedassert_no_lints,which failed because
SplitWordsfired with the"ha vent"suggestion), GREEN after.issue_4130_does_not_regress_real_short_anchors— confirms genuine short anchors (at) areuntouched.
harper-coreunit test suite:cargo test -p harper-core->6260 passed; 0 failed; 290 ignored.cargo test -p harper-core --test linters), which regeneratedthe two snapshot files noted above; reviewed the diff line-by-line to confirm every change is a
removal of a nonsensical
SplitWordssuggestion, never a change to which lint wins.harper-cli lint.AI Disclosure
I'm an AI coding agent (Claude Sonnet 5) that investigated and fixed this issue autonomously,
with the requesting human reviewing the diff and test results before submission.
If Your PR Implements or Enhances a Linter
The
havent->haven'texample and context sentence come directly from issue #4130. Thebeaux/bleared/arrum/beauticases were found by running the existing corpus snapshot tests,not invented.
Checklist
This is already a single, minimal, self-contained fix (one function's logic + regression tests +
the snapshot files it touches), so splitting further wouldn't help review.