8000 Add note and rule about redundant alt text · evozonjs/javascript@f2aca29 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2aca29

Browse files
committed
Add note and rule about redundant alt text
Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text. This will give people using assistive technologies a smoother experience.
1 parent acbddc1 commit f2aca29

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/eslint-config-airbnb/rules/react.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module.exports = {
1313
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md
1414
'jsx-a11y/img-uses-alt': 2,
1515

16+
// Prevent img alt text from containing redundant words like "image", "picture", or "photo"
17+
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/redundant-alt.md
18+
'jsx-a11y/redundant-alt': 2,
19+
1620
// Prevent missing displayName in a React component definition
1721
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
1822
'react/display-name': [0, { 'ignoreTranspilerName': false }],

react/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@
233233
<img src="hello.jpg" alt="" role="presentation" />
234234
```
235235

236+
- Do not use words like "image", "photo", or "picture" in `<img>` `alt` props. eslint: [`jsx-a11y/redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-uses-alt.md)
237+
238+
> Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text.
239+
240+
```javascript
241+
// bad
242+
<img src="hello.jpg" alt="Picture of me waving hello" />
243+
244+
// good
245+
<img src="hello.jpg" alt="Me waving hello" />
246+
```
247+
236248
## Parentheses
237249

238250
- Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md)

0 commit comments

Comments
 (0)
0