Skip to content

fix(core): stop SplitWords treating short non-anchor words as split anchors - #4212

Merged
hippietrail merged 5 commits into
Automattic:masterfrom
vjymisal0:fix/split-words-havent-anchor
Sep 26, 2026
Merged

hippietrail merged 5 commits into
Automattic:masterfrom
vjymisal0:fix/split-words-havent-anchor

Conversation

@vjymisal0

Copy link
Copy Markdown
Contributor

Issues

Fixes #4130

Description

SplitWords' should_defer_to_spellcheck() is meant to prefer a strong single-word spelling
correction (from SpellCheck) over a compound-word split, unless the split includes a genuine
function-word "anchor" (a preposition, determiner, conjunction, pronoun, or adverb) — e.g. at
in atall -> at all.

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." — this is the reported bug.

The fix removes the length-based fallback from is_anchor_split(), so it now only checks tagged
part-of-speech metadata (preposition/determiner/conjunction/pronoun/adverb). Real short anchors
like at/of are unaffected because they're already tagged as prepositions in the curated
dictionary (atall -> at all still works, covered by
issue_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 existing Spelling suggestion)
  • bleared -> bl eared (should defer to the existing Style suggestion)
  • arrum -> arr um
  • beauti -> beau ti

In every case, SplitWords was producing a nonsensical suggestion that overlapped with (and, due
to priority, was shown instead of) an existing, correct SpellCheck/other suggestion. No new
snapshot 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:

$ harper-cli lint test.txt   # "they havent reviewed it yet."
[Typo::SplitWords] (pri 31): `havent` should probably be written as `ha vent`.

CLI after the fix:

$ harper-cli lint test.txt   # "they havent reviewed it yet."
[Spelling::SpellCheck] (pri 63): Did you mean to spell `havent` this way? -> haven't

How Has This Been Tested?

  • Added two regression tests to harper-core/src/linting/split_words.rs:
    • issue_4130_defers_havent_to_spellcheck — RED before the fix (asserted assert_no_lints,
      which failed because SplitWords fired with the "ha vent" suggestion), GREEN after.
    • issue_4130_does_not_regress_real_short_anchors — confirms genuine short anchors (at) are
      untouched.
  • Ran the full harper-core unit test suite: cargo test -p harper-core -> 6260 passed; 0 failed; 290 ignored.
  • Ran the corpus snapshot test (cargo test -p harper-core --test linters), which regenerated
    the two snapshot files noted above; reviewed the diff line-by-line to confirm every change is a
    removal of a nonsensical SplitWords suggestion, never a change to which lint wins.
  • Manually reproduced the original issue and the fix via harper-cli lint.

AI Disclosure

  • I am an agent or I got an agent to do the work autonomously.

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

  • I'm using examples from the bug report / feature request.

The havent -> haven't example and context sentence come directly from issue #4130. The
beaux/bleared/arrum/beauti cases were found by running the existing corpus snapshot tests,
not invented.

Checklist

  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have considered splitting this into smaller pull requests.

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.

vijay-loopr and others added 2 commits August 24, 2026 18:23
…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.
@elijah-potter

Copy link
Copy Markdown
Member

Closing for violating the agent policy.

@elijah-potter

Copy link
Copy Markdown
Member

I'm reopening this PR since the bit of the agent policy it violated was added after this PR was submitted.

@elijah-potter elijah-potter reopened this Sep 24, 2026
Comment thread harper-core/src/linting/split_words.rs Resolved

@elijah-potter elijah-potter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elijah-potter
elijah-potter added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@hippietrail
hippietrail added this pull request to the merge queue Sep 26, 2026
Merged via the queue into Automattic:master with commit f41bec4 Sep 26, 2026
13 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

havent (missing apostrophe) produces nonsensical "ha vent" suggestion

4 participants