Skip to content

Commit b8932b2

Browse files
authored
Merge branch 'master' into more-flow-configuration
2 parents c70217e + e790336 commit b8932b2

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

__tests__/src/rules/img-redundant-alt-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ ruleTester.run('img-redundant-alt', rule, {
5757
{ code: '<UX.Layout>test</UX.Layout>' },
5858
{ code: '<img alt={imageAlt} />' },
5959
{ code: '<img alt />' },
60+
{ code: '<img alt="Photography" />;' },
61+
{ code: '<img alt="ImageMagick" />;' },
6062
].map(parserOptionsMapper),
6163
invalid: [
6264
{ code: '<img alt="Photo of friend." />;', errors: [expectedError] },

docs/rules/img-has-alt.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This rule takes one optional object argument of type object:
1818

1919
For the `components` option, these strings determine which JSX elements (**always including** `<img>`) should be checked for having `alt` prop. This is a good use case when you have a wrapper component that simply renders an `img` element (like in React):
2020

21-
```js
21+
```jsx
2222
// Image.js
2323
const Image = props => {
2424
const {
@@ -42,7 +42,7 @@ return (
4242
);
4343
```
4444

45-
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.** For example:
45+
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. 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.** For example:
4646

4747
#### Bad
4848
```jsx
@@ -85,4 +85,5 @@ function Foo(props) {
8585
<img {...props} alt /> // Has no value
8686
<img {...props} alt={undefined} /> // Has no value
8787
<img {...props} alt={`${undefined}`} /> // Has no value
88+
<img src="foo" role="presentation" /> // Avoid ARIA if it can be achieved without
8889
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eslint-plugin-jsx-a11y",
33
"version": "3.0.2",
4-
"description": "A static analysis linter of jsx and their accessibility with screen readers.",
4+
"description": "Static AST checker for accessibility rules on JSX elements.",
55
"keywords": [
66
"eslint",
77
"eslintplugin",
@@ -42,7 +42,7 @@
4242
"eslint-plugin-flowtype": "^2.29.2",
4343
"eslint-plugin-import": "^2.2.0",
4444
"expect": "^1.20.2",
45-
"flow-bin": "^0.37.4",
45+
"flow-bin": "^0.38.0",
4646
"jest": "^18.1.0",
4747
"jscodeshift": "^0.3.30",
4848
"minimist": "^1.2.0",

src/rules/img-redundant-alt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060

6161
if (typeof value === 'string' && isVisible) {
6262
const hasRedundancy = redundantWords
63-
.some(word => Boolean(value.match(new RegExp(`(?!{)${word}(?!})`, 'gi'))));
63+
.some(word => Boolean(value.match(new RegExp(`(?!{)\\b${word}\\b(?!})`, 'i'))));
6464

6565
if (hasRedundancy === true) {
6666
context.report({

0 commit comments

Comments
 (0)