Skip to content

feat(rules): content/h1-title-alignment warns when the H1 and title share no meaningful word #929 - #1024

Closed
nc9 wants to merge 3 commits into
mainfrom
feat/929-h1-title-alignment
Closed

nc9 wants to merge 3 commits into
mainfrom
feat/929-h1-title-alignment

Conversation

@nc9

@nc9 nc9 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #929

New rule content/h1-title-alignment (page scope, no network): reports a page whose H1 and <title> share no meaningful word, showing both strings. It ships as info, not a warning (see Precision).

Precision (review corpus: 115,556 stored pages, no live crawl, reviewer's script)

  • Before the fixes: 3,283 warns on 46,589 judged pages (7.0%); hand-judged precision 19/70 = 27%.
  • After: 0 warns. 5,742 info mismatches on 45,588 judged pages (12.6%), 39,846 passes. The stricter details.confident subset (page at least two segments deep, not a homepage or generic marketing page, at least three topic words each side) is 125 pages (0.27%). I hand-judged 40 random ones (seed 7): 14 real mismatches (a generic template H1 such as "Which one would you actually pay for?" under a specific title, a homepage title on a contact or listing page, an H1 that is the site logo or an email address), 26 not (marketing pitch under a descriptive title, glued text, synonym pairs): about 35%. That is under the 60% bar, so per the review decision everything is info and confident is only a marker for a future promotion.
  • Time: 8 microseconds per page on the corpus; a 15,000-word heading and title run in under 500 ms (test).

Review fixes applied

  • A: localized roots (/de/, /pt-br/, /en_gb) and /index.* are the homepage; generic marketing pages (/about, /pricing, /features, /contact, /faq, /services, /company, /team, /support, /help plus German, French, Spanish, Portuguese, Italian, Dutch forms, with or without a locale prefix) get details.pageKind, never confident.
  • C: an all-caps pair (AI, UX, EA) is kept as a word. Conflict with the issue's own fixture: "Reddit Visibility Services, SEO & AI Search" under "Be recommended by AI and showed on Google" now shares AI, so it passes. The test uses the same pair without "AI" to cover the mismatch; say if you would rather exempt AI specifically.
  • D: at most 64 words per side, exact stems through a Set before the fuzzy pairs.
  • E: mostly non-Latin title or H1 under a Latin stopword language is skipped; H1 text that looks like code ({, }, @keyframes) is skipped; run-together heading text (a lower-to-upper hump that splits off a stopword, such as TrustedWhen, not carried as written by the other side) is skipped, not judged. The glued text itself is a parser issue: parsed.h1.texts joins separate nodes without a space (about 900 of the corpus's pages).
  • B: silent e and -ing (price/pricing, make/making, hire/hiring), irregular plurals (woman/women), German and Dutch compound heads (Damenschuhe/Schuhe, via a 5-letter substring), camel-case parts, and a generic-word list (free, online, best, new, guide, tool ...) that cannot make a match alone, per language.
  • F: the golden comment is corrected: 500 rows are 459 pass, 31 info, 10 skipped (the synthetic copy mismatches about 6%).
  • G: docs define the homepage, give the prefix rule (at least five letters and at least 80% of the shorter stem), and the stemming claim matches the code.

Registry and counts: rule, content/index.ts, docs page, nav, card, content "(25 rules)" in both indexes, constants.ts 309 to 310, golden perRuleTally 310 and findings +500 (health score unmoved at 51), varyingRules for both corpora, skipOnNoindex and the noindex-skip list.

Smoke (earlier run, isolated HOME): squirrelscan.com 38 pass, 0 warnings; docs.squirrelscan.com all identical-title info.

Tests: h1-title-alignment-929.test.ts (23), noindex-skip, rule-verdict-scope, template-verdict-page-independence, template-verdict-inputs, docs-category-table, meta-string-limits, the canonical golden and the CLI loader test pass (explicit paths). tsgo packages/rules clean; tangly check --strict passes. Agent skill: no change needed.

Second review round (head after this push)

  • Blocker fixed: the first DoS fix bounded word count, not word length. The title and H1 are now clipped to 500 characters before anything runs and each word to 40, so the glue regex and the German/Dutch substring match cannot go quadratic. Regression tests with a 100 ms bound each: a 100,000-letter token, ax100k against aaaaab (de), 64 x 20,000-character shared-prefix tokens (de and en), 100,000 aB humps, 50,000 Foo humps.
  • The glued-text skip checks the H1 only and needs a word that starts in lower case (voorBedrijven, forFree) with a stopword hump; capitalised brands (YouTube, OwnJournal) and a title are never skipped. On the corpus it now skips 77 pages instead of about 900.
  • Silent e: a final e is dropped only from stems longer than five letters; -ing adds it back to a short consonant-vowel-consonant stem (making to make). hope/hop, cute/cut, mate/mat, tape/tap, lace/lac, prime/prim, dining/din, bored/bore, rating/rats no longer collide; price/pricing, make/making, bake/baking, women/woman, Damenschuhe/Schuhe still match.
  • Page-kind words (about, contact, pricing, features, blog, and equivalents) are generic words that cannot match alone.
  • Wording softened in the docs and CHANGELOG: a minority (roughly 10 to 20 percent by hand judgement) of the mismatches are real.
  • Corpus after: 5,719 info and 38,488 pass of 44,207 judged pages.

@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review of #1024 (content/h1-title-alignment). I read the diff only and did not run the tests. CI was still pending when I looked.

The rule is conservative and well documented. It skips on a missing language, several H1s or a title that is only the brand, and it downgrades the homepage to info. I found nothing that blocks the merge.

  • (medium) h1-title-alignment.ts namesBrand: letters.includes(b) with a 3-letter host label (the minimum, label.length >= 3) matches any segment that merely contains those letters. For example, on app.com a title segment like "Application Development" is treated as the brand and dropped from titleStems. A mismatch can then be skipped (too few content words) or missed. Consider requiring a larger minimum label length, or a word-boundary or whole-token match for short brands.
  • (low) namesBrand also accepts b.includes(letters) for any segment of 3 or more letters. A short segment such as "Shop" or "Blog" counts as the brand if the brand label happens to contain it (for example myshop). That stays on the quiet side, but it can hide real mismatches.
  • (low) The stopword lists are folded to ASCII ("fur", "uber"). fold does not map German ß or ligatures like œ, so "daß" and "cœur" will not match their lists. These are minor gaps, but a short comment or a test would document them.
  • (low) The stemmer's de/nl suffix loop and the es/fr/pt/it loop strip only one suffix. For example, "Kindern" becomes "Kinder" while "Kinder" becomes "Kind", so they will not match. The 5-character, 80% prefix rule in sameWord catches some of these, but short words slip through. This only produces false positives, and the tests could cover one or two German and Dutch plural cases.
  • (low) secondLevel in brandForms is a hard-coded list (co, com, and so on). .com.au and .co.uk work, but .org.uk and .gov.uk rely on the same list. The repo already has a "Public suffix data freshness" check, so it may be worth reusing that data (or tldts, if it is a dependency) instead.
  • (nit) clip is applied to h1 and title in both value and details, and again in items. Computing the clipped strings once would be tidier.
  • (nit) The golden test comment says "500 pages that have a document", and the count moves by exactly 500. That is plausible, but it depends on the fixture, so confirm that CI passes.

Test coverage is good: there is a dedicated 929 test, plus updates to the noindex-skip test and the invariance fixture. The CHANGELOG and docs entries are present.

@nc9
nc9 force-pushed the feat/929-h1-title-alignment branch from a74a342 to 78c6364 Compare October 22, 2026 09:38
@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review of content/h1-title-alignment. I read the diff only. I did not run the tests.

I found no correctness bugs and nothing that should block the merge. The rule is info-only, skips when it is unsure, and is bounded per side (64 words). The golden-test and template-invariance fixture updates look consistent with a new page-scoped rule.

  • (low) h1-title-alignment.ts looksGlued: the regex \p{L}*\p{Ll}\p{Lu}\p{L}* is run over the whole, unclipped H1 and title. The 64-word cap only applies inside contentWords, and looksGlued runs before it. A hostile page with a very long letter run, such as a multi-hundred-KB heading with no separators, makes each match attempt scan and backtrack across that run. That is potentially quadratic, and the file's own comment notes the rule timeout cannot interrupt a loop. Consider clipping both strings (for example to a few thousand characters) at the top of run, before latinShare and looksGlued.
  • (low) The header comment and constants (WARN_MIN_WORDS, WARN_MIN_DEPTH, "A warning needs...") describe a warning that does not exist yet. The rule only emits info, with details.confident. Renaming them to CONFIDENT_* would avoid confusion for the future promotion.
  • (nit) In sameWord, the German and Dutch large.includes(small) match needs only 5 letters. A short stem such as stein or haus could match inside unrelated compounds. This only suppresses an info finding, so it is acceptable, but a test for a false-negative case would document the trade-off.
  • (nit) GENERIC_WORDS is a hand-curated list per language. It is fine, but the other languages have no test coverage beyond what the 929 test file may cover. I did not read it fully, so check that each of es, fr, pt, it and nl has at least one pass case and one info case.

…skip, stems silent e safely #929

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review of the new content/h1-title-alignment rule. I read the diff only and did not run the test suite. I found no correctness or security blockers. The rule is info-only and weight 3, so it can't move scores, and its input is bounded (500 characters per side, 64 words, 40 characters per word).

  • (medium) packages/rules/src/content/h1-title-alignment.ts:6 The precision figure disagrees with the docs and changelog. The header comment and the inline comment before status: "info" say a mismatch was a real defect in "about a third" of hand-judged cases. The docs and CHANGELOG say "roughly 10 to 20 percent". Please pick one measured number. It is the stated reason the rule is info and not a warning, so it should be consistent.
  • (low) h1-title-alignment.ts (the WARN_MIN_WORDS and WARN_MIN_DEPTH constants and their comments) These are still named and described as "a warning needs…", but the rule never warns. They only feed details.confident. Rename them to CONFIDENT_MIN_* and update the comments so they don't suggest a warning path exists.
  • (low) h1-title-alignment.ts (sameWord) In German and Dutch, large.includes(small) accepts any stem of 5 or more letters found anywhere inside another stem, not only a compound's head. For example, schuh would match abschuhen or tagebuch would match buch-ish substrings. This is acceptable for an info-level rule. Consider anchoring to endsWith or startsWith to cut false "shared" results, which would hide real mismatches.
  • (low) h1-title-alignment.ts (pageKind and pathDepth) The locale regex ^/[a-z]{2}(?:[-_][a-z]{2,4})? also swallows real two-letter first path segments such as /ai, /qa or /uk. A page like /ai/pricing is then misread, so /ai counts as a localized homepage and the depth is understated. This only affects confident and pageKind, so the impact is small.
  • (low) Test coverage: h1-title-alignment-929.test.ts exists, and I only skimmed it. I'd like explicit cases for these:
    • the glued-word skip, including the YouTube brand exception
    • non-Latin and no-lang skips
    • the German compound match
    • the /ai/... locale-prefix edge above
    • the 64-word cap with a hostile long heading
  • (nit) streaming-rules-canonical-golden.test.ts The comment gives a breakdown of "459 pass, 31 info, 10 skipped", but it sums to 500. Only the 500-finding total is asserted, so the breakdown can drift silently. Either assert the per-status split or drop it from the comment.
  • (nit) h1-title-alignment.ts The module-level MAX_WORDS, MAX_TEXT_CHARS and MAX_WORD_CHARS constants are declared mid-file, after fold. Move them up beside the other constants.
  • (nit) The CHANGELOG entry is a very long single paragraph. A shorter user-facing summary would match the neighbouring entries better, with the detail left in the docs page.

The rule registration, docs index counts (24 to 25), the skipOnNoindex list update and the 309 to 310 tally bumps are all consistent.

@nc9 nc9 mentioned this pull request Oct 26, 2026
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Landed in the v0.0.135 batch (#1151), main commits e75402b..17d778a.

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.

New rule: content/h1-title-alignment - H1 and title share no meaningful words

1 participant