Skip to content

Commit 2beaf83

Browse files
author
Ethan Cohen
committed
Clean up img alt implementation.
1 parent 6840d41 commit 2beaf83

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lib/rules/img-uses-alt.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ module.exports = function(context) {
1818

1919
return {
2020
JSXOpeningElement: function(node) {
21-
var hasAltProp = node.attributes.some(function(attribute, idx, attrs) {
22-
// If the only attribute is a spread attribute, then pass rule.
23-
if (attribute.type === 'JSXSpreadAttribute' && attrs.length === 1) {
21+
var hasAltProp = node.attributes.some(function(attribute) {
22+
// If the attributes contain a spread attribute, then pass rule.
23+
if (attribute.type === 'JSXSpreadAttribute') {
2424
return true;
25-
} else if (attribute.type === 'JSXSpreadAttribute') {
26-
return false;
2725
}
2826

2927
return attribute.name.name.toUpperCase() === 'ALT';
3028
});
3129

32-
if (!hasAltProp) {
30+
if (hasAltProp === false) {
3331
context.report({
3432
node: node,
3533
message: 'IMG element must have alt tag.'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
1414
"lint": "eslint ./",
1515
"test": "npm run lint && npm run unit-test",
16-
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter dot"
16+
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter nyan"
1717
},
1818
"devDependencies": {
1919
"babel-eslint": "5.0.0-beta10",

tests/lib/rules/img-uses-alt.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ruleTester.run('img-uses-alt', rule, {
3939
{code: '<img {...this.props} />', parserOptions: parserOptions}
4040
],
4141
invalid: [
42-
{code: '<img />;', errors: [expectedError], parserOptions: parserOptions}
42+
{code: '<img />;', errors: [expectedError], parserOptions: parserOptions},
43+
{code: '<img src="xyz" />', errors: [expectedError], parserOptions: parserOptions}
4344
]
4445
});

0 commit comments

Comments
 (0)