Skip to content

Commit 66fc68d

Browse files
authored
Merge branch 'master' into greenkeeper/jscodeshift-0.7.0
2 parents d39cc63 + e4ba839 commit 66fc68d

File tree

5 files changed

+13
-401
lines changed

5 files changed

+13
-401
lines changed

__tests__/src/rules/lang-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ ruleTester.run('lang', rule, {
3030
{ code: '<div lang="foo" />;' },
3131
{ code: '<html lang="en" />' },
3232
{ code: '<html lang="en-US" />' },
33+
{ code: '<html lang="zh-Hans" />' },
34+
{ code: '<html lang="zh-Hant-HK" />' },
35+
{ code: '<html lang="zh-yue-Hant" />' },
36+
{ code: '<html lang="ja-Latn" />' },
3337
{ code: '<html lang={foo} />' },
3438
{ code: '<HTML lang="foo" />' },
3539
{ code: '<Foo lang="bar" />' },

docs/rules/lang.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# lang
22

3-
The `lang` prop on the `<html>` element must have a valid value based on ISO country and language codes.
3+
The `lang` prop on the `<html>` element must be a valid IETF's BCP 47 language tag.
44

55
#### References
6+
67
1. [axe-core, valid-lang](https://dequeuniversity.com/rules/axe/3.2/valid-lang)
7-
2. [ISO Language Codes](http://www.w3schools.com/tags/ref_language_codes.asp)
8-
3. [ISO Country Codes](http://www.w3schools.com/tags/ref_country_codes.asp)
8+
2. [Language tags in HTML and XML](https://www.w3.org/International/articles/language-tags/)
9+
3. [IANA Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
910

1011
## Rule details
1112

1213
This rule takes no arguments.
1314

1415
### Succeed
16+
1517
```jsx
1618
<html lang="en">
1719
<html lang="en-US">

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"damerau-levenshtein": "^1.0.6",
6868
"emoji-regex": "^9.0.0",
6969
"has": "^1.0.3",
70-
"jsx-ast-utils": "^2.4.1"
70+
"jsx-ast-utils": "^2.4.1",
71+
"language-tags": "^1.0.5"
7172
},
7273
"peerDependencies": {
7374
"eslint": "^3 || ^4 || ^5 || ^6 || ^7"

src/rules/lang.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// ----------------------------------------------------------------------------
99

1010
import { propName, elementType, getLiteralPropValue } from 'jsx-ast-utils';
11+
import tags from 'language-tags';
1112
import { generateObjSchema } from '../util/schemas';
12-
import ISO_CODES from '../util/attributes/ISO.json';
1313

1414
const errorMessage = 'lang attribute must have a valid value.';
1515

@@ -51,12 +51,7 @@ module.exports = {
5151
return;
5252
}
5353

54-
const hyphen = value.indexOf('-');
55-
const lang = hyphen > -1 ? value.substring(0, hyphen) : value;
56-
const country = hyphen > -1 ? value.substring(3) : undefined;
57-
58-
if (ISO_CODES.languages.indexOf(lang) > -1
59-
&& (country === undefined || ISO_CODES.countries.indexOf(country) > -1)) {
54+
if (tags.check(value)) {
6055
return;
6156
}
6257

0 commit comments

Comments
 (0)