Skip to content

Commit a5d7940

Browse files
committed
Merge pull request #25 from evcohen/develop
[breaking] - Implement multiple rules and refactor getAttributeValue
2 parents 4fabf91 + db98804 commit a5d7940

Some content is hidden

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

44 files changed

+1615
-188
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ Then configure the rules you want to use under the rules section.
7474
- [label-uses-for](docs/rules/label-uses-for.md): Enforce that label elements have the htmlFor attribute
7575
- [redundant-alt](docs/rules/redundant-alt.md): Enforce img alt attribute does not contain the word image, picture, or photo.
7676
- [no-hash-href](docs/rules/no-hash-href.md): Enforce an anchor element's href prop value is not just #.
77+
- [no-invalid-aria](docs/rules/no-invalid-aria.md): Enforce all aria-* properties are valid.
7778
- [valid-aria-role](docs/rules/valid-aria-role.md): Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.
79+
- [valid-aria-proptype](docs/rules/valid-aria-proptype.md): Enforce ARIA state and property values are valid.
80+
- [role-requires-aria](docs/rules/role-requires-aria.md): Enforce that elements with ARIA roles must have all required attributes for that role.
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.
7882

7983
## Contributing
8084
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.

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
# TODO
2-
1. Allow `alt=""` if `role="presentation"` on img-uses-alt rule.

docs/rules/no-invalid-aria.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# no-invalid-aria
2+
3+
Elements cannot use an invalid ARIA attribute. This will fail if it finds an `aria-*` property that is not listed in [WAI-ARIA States and Properties spec](https://www.w3.org/TR/wai-aria/states_and_properties#state_prop_def).
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<!-- Good: Labeled using correctly spelled aria-labelledby -->
12+
<div id="address_label">Enter your address</div>
13+
<input aria-labelledby="address_label">
14+
```
15+
16+
### Fail
17+
18+
```jsx
19+
<!-- Bad: Labeled using incorrectly spelled aria-labeledby -->
20+
<div id="address_label">Enter your address</div>
21+
<input aria-labeledby="address_label">
22+
```
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/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+
```

docs/rules/valid-aria-proptype.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# valid-aria-proptype
2+
3+
ARIA state and property values must be valid.
4+
5+
#### References
6+
1. [Spec](https://www.w3.org/TR/wai-aria/states_and_properties)
7+
2. [AX_ARIA_04](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_04)
8+
9+
## Rule details
10+
11+
This rule takes no arguments.
12+
13+
### Succeed
14+
```jsx
15+
<!-- Good: the aria-hidden state is of type true/false -->
16+
<span aria-hidden="true">foo</span>
17+
```
18+
19+
### Fail
20+
```jsx
21+
<!-- Bad: the aria-hidden state is of type true/false -->
22+
<span aria-hidden="yes">foo</span>
23+
```
24+

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"build": "rimraf lib && babel src --out-dir lib",
2121
"prepublish": "npm run lint && npm run test && npm run build",
2222
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
23-
"lint": "eslint --config .eslintrc.js src tests",
23+
"lint": "eslint --config .eslintrc.js .",
2424
"pretest": "npm run lint",
25-
"test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --compilers js:babel-core/register --reporter nyan"
25+
"test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --compilers js:babel-core/register --reporter dot"
2626
},
2727
"devDependencies": {
2828
"babel-cli": "^6.6.0",
@@ -38,5 +38,8 @@
3838
"engines": {
3939
"node": ">=0.10.0"
4040
},
41-
"license": "MIT"
41+
"license": "MIT",
42+
"dependencies": {
43+
"object-assign": "^4.0.1"
44+
}
4245
}

src/index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ module.exports = {
1010
'no-access-key': require('./rules/no-access-key'),
1111
'label-uses-for': require('./rules/label-uses-for'),
1212
'no-hash-href': require('./rules/no-hash-href'),
13-
'valid-aria-role': require('./rules/valid-aria-role')
13+
'valid-aria-role': require('./rules/valid-aria-role'),
14+
'valid-aria-proptypes': require('./rules/valid-aria-proptypes'),
15+
'no-invalid-aria': require('./rules/no-invalid-aria'),
16+
'role-requires-aria': require('./rules/role-requires-aria'),
17+
'no-unsupported-elements-use-aria': require('./rules/no-unsupported-elements-use-aria')
1418
},
1519
configs: {
1620
recommended: {
@@ -20,15 +24,19 @@ module.exports = {
2024
}
2125
},
2226
rules: {
23-
"jsx-a11y/img-uses-alt": 2,
24-
"jsx-a11y/redundant-alt": 2,
25-
"jsx-a11y/onclick-uses-role": 2,
26-
"jsx-a11y/mouse-events-map-to-key-events": 2,
27-
"jsx-a11y/use-onblur-not-onchange": 2,
28-
"jsx-a11y/no-access-key": 2,
29-
"jsx-a11y/label-uses-for": 2,
30-
"jsx-a11y/no-hash-href": 2,
31-
"jsx-a11y/valid-aria-role": 2
27+
'jsx-a11y/img-uses-alt': 2,
28+
'jsx-a11y/redundant-alt': 2,
29+
'jsx-a11y/onclick-uses-role': 2,
30+
'jsx-a11y/mouse-events-map-to-key-events': 2,
31+
'jsx-a11y/use-onblur-not-onchange': 2,
32+
'jsx-a11y/no-access-key': 2,
33+
'jsx-a11y/label-uses-for': 2,
34+
'jsx-a11y/no-hash-href': 2,
35+
'jsx-a11y/valid-aria-role': 2,
36+
'jsx-a11y/valid-aria-proptypes': 2,
37+
'jsx-a11y/no-invalid-aria': 2,
38+
'jsx-a11y/role-requires-aria': 2,
39+
'jsx-a11y/no-unsupported-elements-use-aria': 2
3240
}
3341
}
3442
}

0 commit comments

Comments
 (0)