Skip to content

Commit f62dcfe

Browse files
author
Ethan Cohen
committed
2 parents 81598c9 + 9b22d92 commit f62dcfe

File tree

97 files changed

+4434
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4434
-262
lines changed

.eslintignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
node_modules/**
2-
reports/**
3-
index.js
1+
node_modules/
2+
reports/
43
lib/

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ module.exports = {
6464
"ignorePattern": "((^import[^;]+;$)|(^\\s*it\\())",
6565
"ignoreUrls": true
6666
} ],
67-
"new-cap": 2,
6867
"no-alert": 2,
6968
"no-confusing-arrow": 2,
7069
"no-caller": 2,
@@ -144,6 +143,7 @@ module.exports = {
144143
"prefer-const": 2,
145144
"prefer-spread": 2,
146145
"prefer-template": 2,
146+
'quotes': [2, 'single', 'avoid-escape'],
147147
"radix": 2,
148148
"semi": 2,
149149
"sort-vars": [ 2, {

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<a href='https://coveralls.io/github/evcohen/eslint-plugin-jsx-a11y?branch=master'>
1515
<img src='https://coveralls.io/repos/github/evcohen/eslint-plugin-jsx-a11y/badge.svg?branch=master' alt='Coverage Status' />
1616
</a>
17+
<a href='https://npmjs.org/package/eslint-plugin-jsx-a11y'>
18+
<img src='https://img.shields.io/npm/dt/eslint-plugin-jsx-a11y.svg?maxAge=2592000'
19+
alt='Total npm downloads' />
20+
</a>
1721
</p>
1822

1923
# eslint-plugin-jsx-a11y
@@ -29,13 +33,13 @@ Ryan Florence built out this awesome runtime-analysis tool called [react-a11y](h
2933

3034
You'll first need to install [ESLint](http://eslint.org):
3135

32-
```
36+
```sh
3337
$ npm i eslint --save-dev
3438
```
3539

3640
Next, install `eslint-plugin-jsx-a11y`:
3741

38-
```
42+
```sh
3943
$ npm install eslint-plugin-jsx-a11y --save-dev
4044
```
4145

@@ -47,9 +51,9 @@ Add `jsx-a11y` to the plugins section of your `.eslintrc` configuration file. Yo
4751

4852
```json
4953
{
50-
"plugins": [
51-
"jsx-a11y"
52-
]
54+
"plugins": [
55+
"jsx-a11y"
56+
]
5357
}
5458
```
5559

@@ -58,27 +62,30 @@ Then configure the rules you want to use under the rules section.
5862

5963
```json
6064
{
61-
"rules": {
62-
"jsx-a11y/rule-name": 2
63-
}
65+
"rules": {
66+
"jsx-a11y/rule-name": 2
67+
}
6468
}
6569
```
6670

6771
## Supported Rules
6872

69-
- [img-uses-alt](docs/rules/img-uses-alt.md): Enforce that img jsx elements use the alt attribute.
70-
- [onclick-uses-role](docs/rules/onclick-uses-role.md): Enforce that non-interactive, visible elements (such as div) that have click handlers use the role attribute.
71-
- [mouse-events-map-to-key-events](docs/rules/mouse-events-map-to-key-events.md): Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for strictly keyboard users.
72-
- [use-onblur-not-onchange](docs/rules/use-onblur-not-onchange.md): Enforce that onBlur is used instead of onChange.
73-
- [no-access-key](docs/rules/no-access-key.md): Enforce that the accessKey prop is not used on any element to avoid complications with keyboard commands used by a screenreader.
74-
- [label-uses-for](docs/rules/label-uses-for.md): Enforce that label elements have the htmlFor attribute
75-
- [redundant-alt](docs/rules/redundant-alt.md): Enforce img alt attribute does not contain the word image, picture, or photo.
76-
- [no-hash-href](docs/rules/no-hash-href.md): Enforce an anchor element's href prop value is not just #.
73+
- [aria-role-supports-attribute](docs/rules/aria-role-supports-attribute.md): Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`.
74+
- [avoid-positive-tabindex](docs/rules/avoid-positive-tabindex.md): Enforce `tabIndex` value is not greater than zero.
75+
- [img-uses-alt](docs/rules/img-uses-alt.md): Enforce that `<img>` JSX elements use the `alt` prop.
76+
- [label-uses-for](docs/rules/label-uses-for.md): Enforce that `<label>` elements have the `htmlFor` prop.
77+
- [mouse-events-map-to-key-events](docs/rules/mouse-events-map-to-key-events.md): Enforce that `onMouseOver`/`onMouseOut` are accompanied by `onFocus`/`onBlur` for keyboard-only users.
78+
- [no-access-key](docs/rules/no-access-key.md): Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screenreader.
79+
- [no-hash-href](docs/rules/no-hash-href.md): Enforce an anchor element's `href` prop value is not just `#`.
80+
- [no-invalid-aria](docs/rules/no-invalid-aria.md): Enforce all `aria-*` props are valid.
81+
- [no-unsupported-elements-use-aria](docs/rules/no-unsupported-elements-use-aria.md): Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.
82+
- [onclick-has-focus](docs/rules/onclick-has-focus.md): Enforce that elements with `onClick` handlers must be focusable.
83+
- [onclick-uses-role](docs/rules/onclick-uses-role.md): Enforce that non-interactive, visible elements (such as `<div>`) that have click handlers use the role attribute.
84+
- [redundant-alt](docs/rules/redundant-alt.md): Enforce `<img>` alt prop does not contain the word "image", "picture", or "photo".
85+
- [role-requires-aria](docs/rules/role-requires-aria.md): Enforce that elements with ARIA roles must have all required attributes for that role.
86+
- [use-onblur-not-onchange](docs/rules/use-onblur-not-onchange.md): Enforce that `onBlur` is used instead of `onChange`.
87+
- [valid-aria-proptype](docs/rules/valid-aria-proptype.md): Enforce ARIA state and property values are valid.
7788
- [valid-aria-role](docs/rules/valid-aria-role.md): Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.
78-
- [no-invalid-aria](docs/rules/no-invalid-aria.md): Enforce all aria-* properties are valid.
79-
80-
## Contributing
81-
Feel free to contribute! I am currently using [Google Chrome's Audit Rules](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules) to map out as rules for this plugin.
8289

8390
## License
8491

TODO.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# aria-role-supports-attribute
2+
3+
Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. Many ARIA attributes (states and properties) can only be used on elements with particular roles. Some elements have implicit roles, such as `<a href="#" />`, which will resolve to `role="link"`.
4+
5+
#### References
6+
1. [AX_ARIA_10](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_10)
7+
2. [Supported States & Properties](https://www.w3.org/TR/wai-aria/roles#supportedState)
8+
9+
## Rule details
10+
11+
This rule takes no arguments.
12+
13+
### Succeed
14+
```jsx
15+
<!-- Good: the radiogroup role does support the aria-required property -->
16+
<ul role="radiogroup" aria-required aria-labelledby="foo">
17+
<li tabIndex="-1" role="radio" aria-checked="false">Rainbow Trout</li>
18+
<li tabIndex="-1" role="radio" aria-checked="false">Brook Trout</li>
19+
<li tabIndex="0" role="radio" aria-checked="true">Lake Trout</li>
20+
</ul>
21+
```
22+
23+
### Fail
24+
25+
```jsx
26+
<!-- Bad: the radio role does not support the aria-required property -->
27+
<ul role="radiogroup" aria-labelledby="foo">
28+
<li aria-required tabIndex="-1" role="radio" aria-checked="false">Rainbow Trout</li>
29+
<li aria-required tabIndex="-1" role="radio" aria-checked="false">Brook Trout</li>
30+
<li aria-required tabIndex="0" role="radio" aria-checked="true">Lake Trout</li>
31+
</ul>
32+
```

docs/rules/avoid-positive-tabindex.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# avoid-positive-tabindex
2+
3+
Avoid positive tabIndex property values to synchronize the flow of the page with keyboard tab order.
4+
5+
#### References
6+
1. [AX_FOCUS_03](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_03)
7+
8+
## Rule details
9+
10+
This rule takes no arguments.
11+
12+
### Succeed
13+
```jsx
14+
<span tabIndex="0">foo</span>
15+
<span tabIndex="-1">bar</span>
16+
<span tabIndex={0}>baz</span>
17+
```
18+
19+
### Fail
20+
```jsx
21+
<span tabIndex="5">foo</span>
22+
<span tabIndex="3">bar</span>
23+
<span tabIndex="1">baz</span>
24+
<span tabIndex="2">never really sure what goes after baz</span>
25+
```
26+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# no-unsupported-elements-use-aria
2+
3+
Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` and/or `aria-*` props.
4+
5+
#### References
6+
1. [AX_ARIA_12](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_12)
7+
8+
## Rule details
9+
10+
This rule takes no arguments.
11+
12+
### Succeed
13+
```jsx
14+
<!-- Good: the meta element should not be given any ARIA attributes -->
15+
<meta charset="UTF-8" />
16+
```
17+
18+
### Fail
19+
```jsx
20+
<!-- Bad: the meta element should not be given any ARIA attributes -->
21+
<meta charset="UTF-8" aria-hidden="false" />
22+
```
23+

docs/rules/onclick-has-focus.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# onclick-has-focus
2+
3+
Enforce that visible elements with onClick handlers must be focusable. Visible means that it is not hidden from a screen reader. Examples of non-interactive elements are `div`, `section`, and `a` elements without a href prop. Elements which have click handlers but are not focusable can not be used by keyboard-only users.
4+
5+
To make an element focusable, you can either set the tabIndex property, or use an element type which is inherently focusable.
6+
7+
Elements that are inherently focusable are as follows:
8+
- `<input>`, `<button>`, `<select>` and `<textarea>` elements which are not disabled
9+
- `<a>` or `<area>` elements with an `href` attribute.
10+
11+
#### References
12+
1. [AX_FOCUS_02](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_02)
13+
2. [MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Keyboard_and_focus)
14+
15+
## Rule details
16+
17+
This rule takes no arguments.
18+
19+
### Succeed
20+
```jsx
21+
<!-- Good: div with onClick attribute is hidden from screen reader -->
22+
<div aria-hidden onClick={() => void 0} />
23+
<!-- Good: span with onClick attribute is in the tab order -->
24+
<span onClick="doSomething();" tabIndex="0">Click me!</span>
25+
<!-- Good: span with onClick attribute may be focused programmatically -->
26+
<span onClick="doSomething();" tabIndex="-1">Click me too!</span>
27+
<!-- Good: anchor element with href is inherently focusable -->
28+
<a href="javascript:void(0);" onClick="doSomething();">Click ALL the things!</a>
29+
<!-- Good: buttons are inherently focusable -->
30+
<button onClick="doSomething();">Click the button :)</a>
31+
```
32+
33+
### Fail
34+
```jsx
35+
<!-- Bad: span with onClick attribute has no tabindex -->
36+
<span onclick="submitForm();">Submit</span>
37+
<!-- Bad: anchor element without href is not focusable -->
38+
<a onclick="showNextPage();">Next page</a>
39+
```

docs/rules/onclick-uses-role.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# onclick-uses-role
22

3-
Enforce visible, non-interactive elements with click handlers use role attribute. Visible means that it is not hidden from a screen reader. Examples of non-interactive elements are `div`, `section`, and `a` elements without a href prop.The purpose of the role attribute is to identify to screenreaders the exact function of an element.
3+
Enforce visible, non-interactive elements with click handlers use role attribute. Visible means that it is not hidden from a screen reader. Examples of non-interactive elements are `div`, `section`, and `a` elements without a href prop. The purpose of the role attribute is to identify to screenreaders the exact function of an element.
4+
5+
#### References
6+
1. [MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Keyboard_and_focus)
47

58
## Rule details
69

@@ -21,5 +24,4 @@ This rule takes no arguments.
2124
<div onClick={() => void 0} {...props} />
2225
<div onClick={() => void 0} aria-hidden={false} />
2326
<a onClick={() => void 0} />
24-
<input onClick={() => void 0} type="hidden" /> // May not be hidden from screenreader ¯\_(ツ)_/¯
25-
```
27+
```

docs/rules/role-requires-aria.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# role-requires-aria
2+
3+
Elements with ARIA roles must have all required attributes for that role.
4+
5+
#### References
6+
1. [Spec](https://www.w3.org/TR/wai-aria/roles)
7+
2. [AX_ARIA_03](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_03)
8+
9+
## Rule details
10+
11+
This rule takes no arguments.
12+
13+
### Succeed
14+
```jsx
15+
<!-- Good: the checkbox role requires the aria-checked state -->
16+
<span role="checkbox" aria-checked="false" aria-labelledby="foo" tabindex="0"></span>
17+
```
18+
19+
### Fail
20+
21+
```jsx
22+
<!-- Bad: the checkbox role requires the aria-checked state -->
23+
<span role="checkbox" aria-labelledby="foo" tabindex="0"></span>
24+
```

0 commit comments

Comments
 (0)