Skip to content

Commit 6a374d4

Browse files
author
Ethan Cohen
committed
Merge latest.
2 parents d43fe11 + edd95d5 commit 6a374d4

26 files changed

+721
-134
lines changed

.eslintrc.js

Lines changed: 0 additions & 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,

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
0.6.2 / 2016-04-08
2+
==================
3+
- [fix] Fix rule details for img-uses-alt: allow alt="" or role="presentation".
4+
5+
6+
0.6.1 / 2016-04-07
7+
==================
8+
- [fix] Do not infer interactivity of components that are not low-level DOM elements.
9+
10+
11+
0.6.0 / 2016-04-06
12+
==================
13+
- [breaking] Allow alt="" when role="presentation" on img-uses-alt rule.
14+
- [new] More descriptive error messaging for img-uses-alt rule.
15+
16+
17+
0.5.2 / 2016-04-05
18+
==================
19+
- [fix] Handle token lists for valid-aria-role.
20+
21+
22+
0.5.1 / 2016-04-05
23+
==================
24+
- [fix] Handle null valued props for valid-aria-role.
25+
26+
27+
0.5.0 / 2016-04-02
28+
==================
29+
- [new] Implement valid-aria-role rule. Based on [AX_ARIA_01](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_01)
30+
31+
32+
0.4.3 / 2016-03-29
33+
==================
34+
- [fix] Handle LogicalExpression attribute types when extracting values. LogicalExpressions are of form `<Component prop={foo || "foobar"} />`
35+
36+
37+
0.4.2 / 2016-03-24
38+
==================
39+
- [fix] Allow component names of form `Object.Property` i.e. `UX.Layout`
40+
41+
42+
0.3.0 / 2016-03-02
43+
==================
44+
- [new] Implement [no-hash-href](docs/rules/no-hash-href.md) rule.
45+
- [fix] Fixed TemplateLiteral AST value building to get more exact values from template strings.
46+
47+
48+
0.2.0 / 2016-03-01
49+
==================
50+
- [new] Implement [redunant-alt](docs/rules/redundant-alt.md) rule.
51+
52+
53+
0.1.2 / 2016-03-01
54+
==================
55+
- Initial pre-release.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Then configure the rules you want to use under the rules section.
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 #.
7777
- [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.
78+
- [valid-aria-proptype](docs/rules/valid-aria-proptype.md): Enforce ARIA state and property values are valid.
7979

8080
## Contributing
8181
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.

docs/rules/img-uses-alt.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ To tell this plugin to also check your `Image` element, specify this in your `.e
4141
}
4242
```
4343

44-
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop for rule to pass. The prop must have an actual value to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.**
44+
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop or use `role="presentation"` for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.**
4545

4646
### Succeed
4747
```jsx
4848
<img src="foo" alt="Foo eating a sandwich." />
4949
<img src="foo" alt={"Foo eating a sandwich."} />
5050
<img src="foo" alt={altText} />
5151
<img src="foo" alt={`${person} smiling`} />
52-
<img src="foo" alt="" role="presentation" /> <!-- Alt text can be an empty string if `role="presentation"` -->
52+
<img src="foo" alt="" />
53+
<img src="foo" role="presentation" />
5354
```
5455

5556
### Fail

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+

docs/rules/valid-aria-role.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to all role defintions can be found at [WAI-ARIA](https://www.w3.org/TR/wai-aria/roles#role_definitions) site.
44

5+
[AX_ARIA_01](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_01)
6+
57
## Rule details
68

79
This rule takes no arguments.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-jsx-a11y",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "A static analysis linter of jsx and their accessibility with screen readers.",
55
"keywords": [
66
"eslint",
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
'label-uses-for': require('./rules/label-uses-for'),
1212
'no-hash-href': require('./rules/no-hash-href'),
1313
'valid-aria-role': require('./rules/valid-aria-role'),
14-
'no-invalid-aria': require('./rules/no-invalid-aria')
14+
'valid-aria-proptypes': require('./rules/valid-aria-proptypes')
1515
},
1616
configs: {
1717
recommended: {
@@ -30,7 +30,7 @@ module.exports = {
3030
"jsx-a11y/label-uses-for": 2,
3131
"jsx-a11y/no-hash-href": 2,
3232
"jsx-a11y/valid-aria-role": 2,
33-
"jsx-a11y/no-invalid-aria": 2
33+
"jsx-a11y/valid-aria-proptypes": 2
3434
}
3535
}
3636
}

src/rules/img-uses-alt.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ module.exports = context => ({
2222
return;
2323
}
2424

25+
const hasRoleProp = hasAttribute(node.attributes, 'role');
26+
const roleValue = getAttributeValue(hasRoleProp);
27+
const isPresentation = hasRoleProp && roleValue.toLowerCase() === 'presentation';
28+
29+
if (isPresentation) {
30+
return;
31+
}
32+
2533
const hasAltProp = hasAttribute(node.attributes, 'alt');
2634

2735
// Missing alt prop error.
2836
if (!hasAltProp) {
2937
context.report({
3038
node,
31-
message: `${nodeType} elements must have an alt prop.`
39+
message: `${nodeType} elements must have an alt prop or use role="presentation".`
3240
});
3341
return;
3442
}
3543

3644
// Check if alt prop is undefined.
37-
const altProp = getAttributeValue(hasAltProp);
38-
39-
// Check if alt prop is ""
40-
const emptyAlt = hasAltProp && hasAltProp.value
41-
&& hasAltProp.value.type === 'Literal'
42-
&& hasAltProp.value.value === "";
43-
44-
const hasRoleProp = hasAttribute(node.attributes, 'role');
45-
const roleProp = getAttributeValue(hasRoleProp);
45+
const altValue = getAttributeValue(hasAltProp);
46+
const isNullValued = hasAltProp.value === null; // <img alt />
4647

47-
// Allow altProp to be "" if `role="presentation"` is present.
48-
const isValid = altProp || (emptyAlt && hasRoleProp && roleProp.toUpperCase() === 'PRESENTATION');
49-
50-
// Undefined alt prop error.
51-
if (!isValid) {
52-
context.report({
53-
node,
54-
message: `${nodeType} alt prop must have a value. You can set alt="" if role="presentation" is applied.`
55-
});
48+
if ((altValue && !isNullValued) || altValue === '') {
5649
return;
5750
}
51+
52+
// Undefined alt prop error.
53+
context.report({
54+
node,
55+
message:
56+
`Invalid alt value for ${nodeType}. Use alt="" or role="presentation" for presentational images.`
57+
});
5858
}
5959
});
6060

src/rules/label-uses-for.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = context => ({
2727

2828
const htmlForAttr = hasAttribute(node.attributes, 'htmlFor');
2929
const htmlForValue = getAttributeValue(htmlForAttr);
30-
const isInvalid = htmlForAttr === false || htmlForValue === null || htmlForValue === undefined;
30+
const isInvalid = htmlForAttr === false || !htmlForValue;
3131

3232
if (isInvalid) {
3333
context.report({

0 commit comments

Comments
 (0)