Skip to content

fix(rules): gate keyword density by language - #1238

Merged
nc9 merged 6 commits into
squirrelscan:mainfrom
WilliamK112:codex/keyword-stuffing-language-1232
Oct 29, 2026
Merged

nc9 merged 6 commits into
squirrelscan:mainfrom
WilliamK112:codex/keyword-stuffing-language-1232

Conversation

@WilliamK112

@WilliamK112 WilliamK112 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • gate keyword-density scoring by the measured copy's script instead of trusting the page-controlled lang attribute
  • skip only when non-Latin letters strictly outnumber Latin letters, so Latin-script copy is still scored for unsupported, unknown, or misleading language tags
  • preserve English behavior when no usable language is declared, and keep incl and vat as English-only price-note terms so repeated use remains detectable on non-English pages
  • document the script-aware behavior and add regressions for supported subtags, unknown/no-language tags, unsupported Latin-script languages, misleading lang=ru, natural Russian copy, and German body-fallback price terms

Closes #1232.

Verification

  • final head bun run scripts/test-suites.ts --run rules — 8,138 passed, 25 todo, 0 failed
  • bun test ./packages/rules/tests/keyword-stuffing.test.ts — 59 passed, 0 failed
  • full rest suite — 1,900 passed, 1 skipped, 0 failed
  • bun run typecheck — all workspaces passed
  • bun run docs:check — 62 passed, 0 failed
  • bunx oxfmt --check and bunx oxlint
  • repository detect-secrets==1.5.0 scan
  • git diff --check

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line.

Docs: docs/rules/content/keyword-stuffing.mdx. Skill: none.

@nc9 nc9 added bug Something isn't working rules packages/rules — audit rule definitions labels Oct 28, 2026

nc9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: ab68221

Verdict: changes requested, one blocking item. Thanks for picking up #1232. Logic, tests and docs are in good shape, CI is green and the DCO sign-off is present.

Medium (blocking)

Low

  • Behaviour change worth a line in the PR description: pages declaring ja, zh or ko now return skipped for the whole check, where before their Latin-script words were still scored. That matches the intent of content/keyword-stuffing: function-word lists beyond the listed languages; gate incl/vat to English #1232 and the updated test, but it is a visible change in reports.
  • primaryLangSubtag already maps malformed values such as en_US or an empty lang to a usable tag or "", so those keep the English path. A test for lang="en_US" (still checked, not skipped) would lock that in.

Checked and fine

  • incl and VAT are now ignored only for English or unset language, and a German page flags them.
  • No new regexes, loops or dependencies, and the rule docs are updated alongside the code.

@WilliamK112
WilliamK112 force-pushed the codex/keyword-stuffing-language-1232 branch from d7bbe5e to e5acf91 Compare October 28, 2026 21:39
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed the review in e5acf91:

  • moved the changelog entry into the current [Unreleased] / Fixed section
  • added a regression proving lang="en_US" still uses the English price-note exclusions
  • called out the visible ja / zh / ko skipped result in the PR summary

The targeted rule test now passes 42 cases, and the rules package typecheck, targeted lint, changelog extraction check, and diff check pass locally.

@WilliamK112
WilliamK112 force-pushed the codex/keyword-stuffing-language-1232 branch from e5acf91 to 23da114 Compare October 28, 2026 21:56

nc9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 23da114

Verdict: looks good. Thanks for the updates. The CHANGELOG bullet now sits under [Unreleased], and the new head adds the lang="en_US" test, which covers the earlier findings. CI is green, the DCO sign-off is present, there is no new runtime dependency, and the rule docs are updated.

Low

  • Pages declaring any language without a function-word list (for example ru, ja, zh, ko) now return skipped for the whole check, where before they were scored against English words. That is a visible change in reports and a broader gate than gating incl and VAT to English. It is a maintainer call whether skipping is the right default or whether those languages should still run with the English list.

@nc9

nc9 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: 23da114

Thanks @WilliamK112, quick turnaround again. The incl/vat gating, the docs and the subtag handling (ru-RU, EN-gb, en_US) all look right. One design change before merge, and it's on us: the acceptance criteria in #1232 allowed the "skip the language" route, and on reflection it opens a hole.

  1. (medium) Declaring an unsupported language turns the rule off. This is a scored warning, so an English page stuffed with keywords can opt out with <html lang="ru"> (or any unlisted tag). Please make the gate script-aware instead of lang-aware:

    • skip only when most of the measured copy's letters are in a script we have no function-word list for (Cyrillic, Greek, Arabic, Hebrew, Devanagari, Thai and so on);
    • otherwise keep scoring with the English exclusions, whatever lang says.

    A simple letter-script tally over the tokens you already build is enough.

  2. (medium) Regression for Latin-script languages without a list. For the same reason, lang="ja", pl, tr, sv, cs, id and vi pages are skipped entirely today. Latin-script stuffing on them was caught before. The script-aware gate fixes this too. Please restore the ja test to assert that Latin-script stuffing still warns.

  3. (low) Undetermined tags. und, mul, zxx and unknown two- or three-letter tags should read as "no usable language" (English behaviour), not a skip.

  4. (low) Tests. Please add:

    • ru-RU, en-GB, EN, x-default and lang="" cases;
    • an English stuffed page with lang="ru" that still warns;
    • a natural Russian paragraph that doesn't warn (assert no warning, not just a skip);
    • the German price-term case on the body-fallback path as well as <main>.
  5. (low) Please run scripts/test-suites.ts --run rules and --run rest on the final head, since fixtures such as template-invariance-measured.json can shift.

Verdict: needs changes (1 and 2). The rest is small.

@nc9

nc9 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Sorry for the mixed signals, @WilliamK112. The earlier "looks good" came from an automated review pass that ran before we made a design call on this PR. The latest review stands: please switch to the script-aware gate, so an unsupported lang alone never turns the rule off. Your newest commit (the malformed-lang tests) is still useful and can stay.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed the latest review in f72c002.

  • The rule no longer trusts lang to disable scoring. It now skips only when most measured letters use a non-Latin script for which there is no function-word list.
  • Latin-script copy is scored even for unsupported or misleading language tags.
  • Added coverage for ru-RU, en-GB, EN, x-default, an empty tag, und/mul/zxx, unknown 2/3-letter tags, unsupported Latin-script languages, misleading lang=ru, natural Russian copy, and German body-fallback price terms.
  • Updated the rule documentation and changelog to describe the script-aware behavior.

Validation:

  • focused keyword-stuffing tests: 59 pass, 0 fail
  • full rules suite: 8138 pass, 25 todo, 0 fail
  • full rest suite: 1900 pass, 1 skip, 0 fail
  • bun run typecheck
  • bun run docs:check
  • bunx oxfmt --check / bunx oxlint
  • git diff --check

@nc9

nc9 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: f72c002

Thanks @WilliamK112, this is exactly what we asked for.

  • The lang skip is gone. hasUnsupportedScriptMajority skips only when non-Latin letters strictly outnumber Latin ones in the measured copy, so Latin copy is always scored and lang="ru" on an English page no longer opts out.
  • The ja/pl/tr/sv/cs/id/vi regression is fixed, and the tests assert warn on Latin stuffing.
  • und/mul/zxx/xx/qaa/empty/x-default behave as no language.
  • All the requested tests are there, including German price terms on the body-fallback path.
  • The tally is one linear pass over already-capped tokens, so there's no new input-cost risk. Han/Kana/Hangul stay unscored, and a 50/50 tie is scored.

One small thing before merge:

  1. The PR description is stale. It still says ja/zh/ko pages are skipped and quotes a --run rules result from before f72c002. Please rerun scripts/test-suites.ts --run rules on the final head and update the description to match the script-aware behaviour.

Notes, no change needed:

  • Padding a page with more Cyrillic than Latin letters can still skip the rule, but that costs visible main copy, which is acceptable for this warning.
  • A short non-Latin page now reports skipped before the under-100-words info.

Verdict: good to merge once the description is updated. A description-only edit doesn't need another review round.

nc9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 34f5c72

Thanks @WilliamK112. Verdict: the code is unchanged since the last review; one item from that review is still open (the PR description), so this is not ready yet.

The only new commit is a merge of main (34f5c72b, bringing in #1240). The script-aware gate in f72c0023 is identical to what was reviewed, so the code findings stand as resolved.

Still open from the last review:

  1. (low) The PR description is stale. It still says pages declaring ja, zh or ko report the whole check as skipped, that the gate skips on a declared unsupported language, and it quotes --run rules as 8,120 passed. The current behaviour is the script-aware gate, and the f72c002 run you posted was 8,138 passed. Please update the Summary and Verification sections to match.

CI on this head: every finished check is green; CLI tests were still running when I looked.

Verdict: good to merge once the description is updated, pending maintainer review.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Updated the PR description to match the script-aware final implementation and reran the requested suite on final head 34f5c72:

  • bun run scripts/test-suites.ts --run rules
  • 8,138 passed, 25 todo, 0 failed (8,163 tests across 236 files)

No code changes were needed for this follow-up.

@nc9

nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: 34f5c72

A merge of main only. The #1232 patch is identical to f72c002, which was reviewed clean, and the description now matches the script-aware behaviour, with a fresh rules and rest run. Good to merge.

nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 75c5a16

Thanks @WilliamK112. Verdict: no code change since the last review, ready for a maintainer merge decision.

The only new commit is a merge of main (75c5a167, which brings in #1243 and touches only tech-detect). The script-aware gate is identical to f72c0023, which resolved the maintainer's design decision (an unsupported lang alone never turns the rule off). The PR description now matches that behaviour and reports a rules run of 8,138 passed.

Conventions: DCO is present, no new runtime dependency, rule docs and CHANGELOG are updated. CI on this head: all checks green.

@nc9

nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@WilliamK112 this is approved and ready to merge, but v0.0.140 just shipped and the PR now conflicts with main, almost certainly in CHANGELOG.md: the old [Unreleased] bullets moved into the v0.0.140 section. Could you merge main once more and keep your bullet under the new ## [Unreleased] heading? Please leave the released sections untouched. If the only new commit is that merge, it goes straight in with no further review round.

@nc9
nc9 force-pushed the codex/keyword-stuffing-language-1232 branch from df033f6 to b2f48cc Compare October 29, 2026 10:27
@nc9
nc9 force-pushed the codex/keyword-stuffing-language-1232 branch from b2f48cc to 45ae98e Compare October 29, 2026 10:28
@nc9

nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Update-branch (merge of main, no rebase): head 45ae98e = merge commit, parents 75c5a16 (approved) and 660dcfc (main tip). Non-CHANGELOG patch unchanged: git patch-id --stable 44b330096f62edf14ffde2fa4f472729c1faec6c for both, same file list. CHANGELOG: the PR's own bullet is under [Unreleased] (Fixed); released sections equal their tags. Pin for merge once checks are green: 45ae98e.

@nc9
nc9 merged commit 421dbf0 into squirrelscan:main Oct 29, 2026
25 of 26 checks passed
@nc9

nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Merged. Thank you @WilliamK112, the language gate keeps keyword density honest for pages written in languages the stop-word lists do not cover. (Nik)

@nc9 nc9 mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rules packages/rules — audit rule definitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

content/keyword-stuffing: function-word lists beyond the listed languages; gate incl/vat to English

2 participants