Skip to content

Commit f87561d

Browse files
committed
Merge branch 'master' of github.com:evcohen/eslint-plugin-jsx-a11y into fix-aria-1-2-test-failures
2 parents 8059f51 + 4c60546 commit f87561d

File tree

8 files changed

+62
-437
lines changed

8 files changed

+62
-437
lines changed

.travis.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
language: node_js
22
node_js:
3+
- "14"
34
- "12"
45
- "10"
5-
- "9"
66
- "8"
7-
- "7"
87
- "6"
9-
- "5"
108
- "4"
119
cache:
1210
yarn: true
@@ -29,6 +27,7 @@ env:
2927
global:
3028
- TEST=true
3129
matrix:
30+
- ESLINT=7
3231
- ESLINT=6
3332
- ESLINT=5
3433
- ESLINT=4
@@ -45,19 +44,15 @@ matrix:
4544
env: ESLINT=5
4645
- node_js: "4"
4746
env: ESLINT=6
48-
- node_js: "5"
49-
env: ESLINT=5
47+
- node_js: "4"
48+
env: ESLINT=7
5049
- node_js: "6"
5150
env: ESLINT=6
51+
- node_js: "6"
52+
env: ESLINT=7
53+
- node_js: "8"
54+
env: ESLINT=7
5255
allow_failures:
53-
- node_js: "7"
54-
env: ESLINT=6
55-
- node_js: "5"
56-
env: ESLINT=6
57-
- node_js: "5"
58-
env: ESLINT=4
59-
- node_js: "5"
60-
env: ESLINT=3
6156
- node_js: "4"
6257
env: ESLINT=4
6358
- node_js: "4"

__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" />' },

__tests__/src/rules/mouse-events-have-key-events-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,21 @@ ruleTester.run('mouse-events-have-key-events', rule, {
3939
code: '<div onMouseOver={handleMouseOver} onFocus={handleFocus} {...props} />;',
4040
},
4141
{ code: '<div />;' },
42+
{ code: '<div onBlur={() => {}} />' },
43+
{ code: '<div onFocus={() => {}} />' },
4244
{ code: '<div onMouseOut={() => void 0} onBlur={() => void 0} />' },
4345
{ code: '<div onMouseOut={() => void 0} onBlur={() => void 0} {...props} />' },
4446
{ code: '<div onMouseOut={handleMouseOut} onBlur={handleOnBlur} />' },
4547
{ code: '<div onMouseOut={handleMouseOut} onBlur={handleOnBlur} {...props} />' },
48+
{ code: '<MyElement />' },
49+
{ code: '<MyElement onMouseOver={() => {}} />' },
50+
{ code: '<MyElement onMouseOut={() => {}} />' },
51+
{ code: '<MyElement onBlur={() => {}} />' },
52+
{ code: '<MyElement onFocus={() => {}} />' },
53+
{ code: '<MyElement onMouseOver={() => {}} {...props} />' },
54+
{ code: '<MyElement onMouseOut={() => {}} {...props} />' },
55+
{ code: '<MyElement onBlur={() => {}} {...props} />' },
56+
{ code: '<MyElement onFocus={() => {}} {...props} />' },
4657
].map(parserOptionsMapper),
4758
invalid: [
4859
{ code: '<div onMouseOver={() => void 0} />;', errors: [mouseOverError] },

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: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,48 @@
3030
"jest": "jest --coverage __tests__/**/*"
3131
},
3232
"devDependencies": {
33-
"@babel/cli": "^7.4.4",
34-
"@babel/core": "^7.0.0",
35-
"@babel/plugin-transform-flow-strip-types": "^7.2.3",
36-
"babel-eslint": "^10.0.1",
37-
"babel-jest": "^24.0.0",
33+
"@babel/cli": "^7.10.1",
34+
"@babel/core": "^7.10.2",
35+
"@babel/plugin-transform-flow-strip-types": "^7.10.1",
36+
"babel-eslint": "^10.1.0",
37+
"babel-jest": "^24.9.0",
3838
"babel-preset-airbnb": "^5.0.0",
39-
"coveralls": "^3.0.1",
40-
"eslint": "^3 || ^4 || ^5 || ^6",
41-
"eslint-config-airbnb-base": "^14.0.0",
42-
"eslint-plugin-flowtype": "^5.0.0",
43-
"eslint-plugin-import": "^2.18.0",
44-
"estraverse": "^4.2.0",
39+
"coveralls": "^3.1.0",
40+
"eslint": "^3 || ^4 || ^5 || ^6 || ^7",
41+
"eslint-config-airbnb-base": "^14.2.0",
42+
"eslint-plugin-flowtype": "^5.1.3",
43+
"eslint-plugin-import": "^2.21.2",
44+
"estraverse": "^4.3.0",
4545
"expect": "^24.3.1",
4646
"flow-bin": "^0.113.0",
47-
"in-publish": "^2.0.0",
48-
"jest": "^24.0.0",
49-
"jscodeshift": "^0.6.0",
50-
"minimist": "^1.2.0",
47+
"in-publish": "^2.0.1",
48+
"jest": "^24.9.0",
49+
"jscodeshift": "^0.7.0",
50+
"minimist": "^1.2.5",
5151
"object.assign": "^4.1.0",
52-
"rimraf": "^3.0.0",
53-
"safe-publish-latest": "^1.1.1",
52+
"rimraf": "^3.0.2",
53+
"safe-publish-latest": "^1.1.4",
5454
"to-ast": "^1.0.0"
5555
},
5656
"engines": {
5757
"node": ">=4.0"
5858
},
5959
"license": "MIT",
6060
"dependencies": {
61-
"@babel/runtime": "^7.4.5",
61+
"@babel/runtime": "^7.10.2",
6262
"aria-query": "^4.0.2",
63-
"array-includes": "^3.0.3",
63+
"array-includes": "^3.1.1",
6464
"ast-types-flow": "^0.0.7",
65-
"axe-core": "^3.5.2",
66-
"axobject-query": "^2.1.1",
67-
"damerau-levenshtein": "^1.0.4",
65+
"axe-core": "^3.5.4",
66+
"axobject-query": "^2.1.2",
67+
"damerau-levenshtein": "^1.0.6",
6868
"emoji-regex": "^9.0.0",
6969
"has": "^1.0.3",
70-
"jsx-ast-utils": "^2.2.1"
70+
"jsx-ast-utils": "^2.4.1",
71+
"language-tags": "^1.0.5"
7172
},
7273
"peerDependencies": {
73-
"eslint": "^3 || ^4 || ^5 || ^6"
74+
"eslint": "^3 || ^4 || ^5 || ^6 || ^7"
7475
},
7576
"jest": {
7677
"coverageReporters": [

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

src/rules/mouse-events-have-key-events.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Rule Definition
99
// ----------------------------------------------------------------------------
1010

11+
import { dom } from 'aria-query';
1112
import { getProp, getPropValue } from 'jsx-ast-utils';
1213
import { generateObjSchema } from '../util/schemas';
1314

@@ -26,6 +27,12 @@ module.exports = {
2627

2728
create: (context) => ({
2829
JSXOpeningElement: (node) => {
30+
const { name } = node.name;
31+
32+
if (!dom.get(name)) {
33+
return;
34+
}
35+
2936
const { attributes } = node;
3037

3138
// Check onmouseover / onfocus pairing.

0 commit comments

Comments
 (0)