Post-merge-review: Fix template-require-lang-attribute: validate every BCP47 subtag (single table)#2683
Conversation
Port only validated parts[0] against a small set; upstream validates every hyphen-separated subtag (region/script). Add the missing country-codes table and traverse all subtags. lang="en-XX" is now correctly flagged.
lib/utils/country-codes.js
Outdated
There was a problem hiding this comment.
do we have to maintain this ourselves? can we use a library and make it someone else's problem?
There was a problem hiding this comment.
yes, maybe language-tags (mattcg) is the right fit? one dep, active, backed by the IANA registry, and it gives us deprecation suggestions for free. We can drop all 628 lines of country-codes.js. Only wrinkle: v2
▎ requires Node ≥22 and this repo's engines.node is >= 20.19,
There was a problem hiding this comment.
is there a prior version that support 20?
There was a problem hiding this comment.
could try to pin to 1.0.9 https://www.npmjs.com/package/language-tags?activeTab=versions
There was a problem hiding this comment.
fixed it now.
language-tags rejects deprecated grandfathered tags (i-klingon → use tlh). The previous validator also rejected those, so no test regression — but consumer templates relying on those tags would now lint-fail. Not in any test today; just worth flagging (claude).
9964ce4 to
0a7da06
Compare
- Drop lib/utils/country-codes.js (628 lines). - Use language-tags (registry-backed validation via the IANA language-subtag-registry transitive dep) instead of a per-subtag allowlist; keep the empty/whitespace early-return. - Pinned to ^1.0.9 (last CJS line; v2.x is ESM). Behavioral note: language-tags rejects deprecated grandfathered tags (e.g. `i-klingon`, preferred value `tlh`). The previous hand-rolled validator also rejected `i-klingon` (its subtags weren't in the table, nor was the whole tag), so existing tests are unchanged — but consumer templates relying on deprecated tags would now be flagged.
Port only validated parts[0] against a small set; upstream validates every hyphen-separated subtag. Merge COMMON_LANG_CODES and COUNTRY_CODES into a single set and match upstream's 'every subtag OR whole tag in table' semantics. Fixes:
Cowritten by claude