Skip to content

Commit 4fab3be

Browse files
committed
Replace hand-maintained BCP47 table with language-tags
- 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.
1 parent 0a7da06 commit 4fab3be

File tree

5 files changed

+21
-843
lines changed

5 files changed

+21
-843
lines changed

lib/rules/template-require-lang-attribute.js

Lines changed: 2 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,4 @@
1-
const COUNTRY_CODES = require('../utils/country-codes');
2-
3-
// Common valid BCP 47 primary language subtags (not exhaustive, but covers the most common).
4-
// Used as a fast-path check for the primary subtag; full validation of every
5-
// hyphen-separated subtag is performed against COUNTRY_CODES (mirroring
6-
// ember-template-lint's upstream behavior).
7-
const COMMON_LANG_CODES = new Set([
8-
'aa',
9-
'ab',
10-
'af',
11-
'ak',
12-
'am',
13-
'an',
14-
'ar',
15-
'as',
16-
'av',
17-
'ay',
18-
'az',
19-
'ba',
20-
'be',
21-
'bg',
22-
'bh',
23-
'bi',
24-
'bm',
25-
'bn',
26-
'bo',
27-
'br',
28-
'bs',
29-
'ca',
30-
'ce',
31-
'ch',
32-
'co',
33-
'cr',
34-
'cs',
35-
'cu',
36-
'cv',
37-
'cy',
38-
'da',
39-
'de',
40-
'dv',
41-
'dz',
42-
'ee',
43-
'el',
44-
'en',
45-
'eo',
46-
'es',
47-
'et',
48-
'eu',
49-
'fa',
50-
'ff',
51-
'fi',
52-
'fj',
53-
'fo',
54-
'fr',
55-
'fy',
56-
'ga',
57-
'gd',
58-
'gl',
59-
'gn',
60-
'gu',
61-
'gv',
62-
'ha',
63-
'he',
64-
'hi',
65-
'ho',
66-
'hr',
67-
'ht',
68-
'hu',
69-
'hy',
70-
'hz',
71-
'ia',
72-
'id',
73-
'ie',
74-
'ig',
75-
'ii',
76-
'ik',
77-
'io',
78-
'is',
79-
'it',
80-
'iu',
81-
'ja',
82-
'jv',
83-
'ka',
84-
'kg',
85-
'ki',
86-
'kj',
87-
'kk',
88-
'kl',
89-
'km',
90-
'kn',
91-
'ko',
92-
'kr',
93-
'ks',
94-
'ku',
95-
'kv',
96-
'kw',
97-
'ky',
98-
'la',
99-
'lb',
100-
'lg',
101-
'li',
102-
'ln',
103-
'lo',
104-
'lt',
105-
'lu',
106-
'lv',
107-
'mg',
108-
'mh',
109-
'mi',
110-
'mk',
111-
'ml',
112-
'mn',
113-
'mr',
114-
'ms',
115-
'mt',
116-
'my',
117-
'na',
118-
'nb',
119-
'nd',
120-
'ne',
121-
'ng',
122-
'nl',
123-
'nn',
124-
'no',
125-
'nr',
126-
'nv',
127-
'ny',
128-
'oc',
129-
'oj',
130-
'om',
131-
'or',
132-
'os',
133-
'pa',
134-
'pi',
135-
'pl',
136-
'ps',
137-
'pt',
138-
'qu',
139-
'rm',
140-
'rn',
141-
'ro',
142-
'ru',
143-
'rw',
144-
'sa',
145-
'sc',
146-
'sd',
147-
'se',
148-
'sg',
149-
'si',
150-
'sk',
151-
'sl',
152-
'sm',
153-
'sn',
154-
'so',
155-
'sq',
156-
'sr',
157-
'ss',
158-
'st',
159-
'su',
160-
'sv',
161-
'sw',
162-
'ta',
163-
'te',
164-
'tg',
165-
'th',
166-
'ti',
167-
'tk',
168-
'tl',
169-
'tn',
170-
'to',
171-
'tr',
172-
'ts',
173-
'tt',
174-
'tw',
175-
'ty',
176-
'ug',
177-
'uk',
178-
'ur',
179-
'uz',
180-
've',
181-
'vi',
182-
'vo',
183-
'wa',
184-
'wo',
185-
'xh',
186-
'yi',
187-
'yo',
188-
'za',
189-
'zh',
190-
'zu',
191-
]);
1+
const tags = require('language-tags');
1922

1933
const DEFAULT_CONFIG = {
1944
validateValues: true,
@@ -198,30 +8,7 @@ function isValidLangTag(value) {
1988
if (!value || !value.trim()) {
1999
return false;
20010
}
201-
const normalized = value.trim().toLowerCase();
202-
const parts = normalized.split('-');
203-
204-
// Primary subtag must be a known language code. Keep the original
205-
// COMMON_LANG_CODES fast-path so bare tags like "zh" remain valid even
206-
// when they are not present in the full country-codes table.
207-
if (!COMMON_LANG_CODES.has(parts[0])) {
208-
// Fallback: the whole value may be a registered grandfathered/irregular
209-
// tag (e.g. "zh-hant", "sgn-gb").
210-
return COUNTRY_CODES.includes(normalized);
211-
}
212-
213-
// Validate every remaining hyphen-separated subtag (region / script /
214-
// variant) against the full country-codes table, mirroring upstream
215-
// ember-template-lint. A whole-string match against COUNTRY_CODES is
216-
// also accepted to cover multi-part registered tags.
217-
if (parts.length === 1) {
218-
return true;
219-
}
220-
221-
return (
222-
parts.slice(1).every((p) => COUNTRY_CODES.includes(p)) ||
223-
COUNTRY_CODES.includes(normalized)
224-
);
11+
return tags(value.trim()).valid();
22512
}
22613

22714
function parseConfig(config) {

0 commit comments

Comments
 (0)