Skip to content

Commit d80fa53

Browse files
christianvueringsbeefancohen
authored andcommitted
[fix] Linter threw JS error when role is undefined (#53)
``` TypeError: roleValue.toLowerCase is not a function ```
1 parent 67c7556 commit d80fa53

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/rules/img-has-alt.js

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

2525
const roleProp = getAttribute(node.attributes, 'role');
2626
const roleValue = getAttributeValue(roleProp);
27-
const isPresentation = roleProp && roleValue.toLowerCase() === 'presentation';
27+
const isPresentation = roleProp && typeof roleValue === 'string' && roleValue.toLowerCase() === 'presentation';
2828

2929
if (isPresentation) {
3030
return;

tests/src/rules/img-has-alt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ ruleTester.run('img-has-alt', rule, {
129129
{ code: '<img alt />;', errors: [ altValueError('img') ], parserOptions },
130130
{ code: '<img alt={undefined} />;', errors: [ altValueError('img') ], parserOptions },
131131
{ code: '<img src="xyz" />', errors: [ missingPropError('img') ], parserOptions },
132+
{ code: '<img role />', errors: [ missingPropError('img') ], parserOptions },
132133
{ code: '<img {...this.props} />', errors: [ missingPropError('img') ], parserOptions },
133134
{ code: '<img alt={false || false} />', errors: [ altValueError('img') ], parserOptions },
134135

0 commit comments

Comments
 (0)