Skip to content

feat(rules): i18n/hreflang validates language and region codes - #1109

Closed
nc9 wants to merge 1 commit into
mainfrom
feat/hreflang-code-validation-3137
Closed

nc9 wants to merge 1 commit into
mainfrom
feat/hreflang-code-validation-3137

Conversation

@nc9

@nc9 nc9 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Part 1 of squirrelscan/repo#3137 (private issue stays open for return-link checking).

Extends page-scope i18n/hreflang with a hreflang-codes warn check: each value must be x-default or language[-script][-region], case-insensitive. Language: ISO 639-1 (embedded list, plus legacy iw/in/ji) or any 3 letters. Script: 4 letters. Region: ISO 3166-1 alpha-2 (embedded list) or 3-digit UN M.49. Flags en_US (suggests en-US), en-uk (region UK suggests GB; uk stays valid as a language), bad languages/regions, extra subtags.

Format only: no return-link checking. No new rule, no rule-count change, no storage/crawler/engine changes.

Docs updated (docs/rules/i18n/hreflang.mdx, CHANGELOG Unreleased). Skill: no change needed.

Gates: new test (12) + hreflang-final-url-827 + hreflang-redirect-827-e2e pass; rules tsgo clean; tangly check --strict, check-links, glossary --check pass.

@claude

claude Bot commented Oct 24, 2026

Copy link
Copy Markdown

Review of the new hreflang-codes check. The change is small and well tested, and I found no blocking problems.

  • (low) packages/rules/src/i18n/hreflang.ts: the new validator accepts X-Default case-insensitively, but the existing hasXDefault check still uses a case-sensitive hreflang === "x-default". A page with only hreflang="X-Default" passes the code check and still gets a false hreflang-xdefault warning. The new test only covers the code check, so it doesn't catch this. Either lowercase the comparison there or reject the capitalised form.
  • (low) hreflangProblem accepts any 3-letter language and any 4-letter script by shape only. This is documented, so the check can miss typos such as xyz. That's an acceptable tradeoff, but a short code comment would help.
  • (nit) The language list is hardcoded. Retired region codes such as an and cs are rejected, which seems right. A one-line pointer to the source of the lists would help whoever updates them next.
  • (nit) The underscore suggestion only uppercases 2-letter parts, so a 4-letter script comes through as written (zh_hant_TW → zh-hant-TW). The suggestion is still valid, but it isn't canonical casing.
  • (nit) A test that X-Default alone doesn't trigger the missing x-default warning would document the intended behaviour.

The docs and CHANGELOG entry look good.

@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.134 batch (#1149), main commits d54ad3e.

@nc9 nc9 closed this Oct 26, 2026
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.

1 participant