7
7
// Rule Definition
8
8
// ----------------------------------------------------------------------------
9
9
10
- import { getProp , getPropValue , elementType } from 'jsx-ast-utils' ;
10
+ import { getProp , getLiteralPropValue , elementType } from 'jsx-ast-utils' ;
11
11
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader' ;
12
12
13
13
const REDUNDANT_WORDS = [
@@ -20,11 +20,6 @@ const errorMessage = 'Redundant alt attribute. Screen-readers already announce '
20
20
'`img` tags as an image. You don\'t need to use the words `image`, ' +
21
21
'`photo,` or `picture` in the alt prop.' ;
22
22
23
- const validTypes = [
24
- 'LITERAL' ,
25
- 'TEMPLATELITERAL' ,
26
- ] ;
27
-
28
23
module . exports = context => ( {
29
24
JSXOpeningElement : node => {
30
25
const type = elementType ( node ) ;
@@ -38,20 +33,10 @@ module.exports = context => ({
38
33
return ;
39
34
}
40
35
41
- // Only check literals, as we should not enforce variable names :P
42
- const normalizedType = altProp . value &&
43
- altProp . value . type . toUpperCase ( ) === 'JSXEXPRESSIONCONTAINER' ?
44
- altProp . value . expression . type . toUpperCase ( ) :
45
- altProp . value . type . toUpperCase ( ) ;
46
-
47
- if ( validTypes . indexOf ( normalizedType ) === - 1 ) {
48
- return ;
49
- }
50
-
51
- const value = getPropValue ( altProp ) ;
36
+ const value = getLiteralPropValue ( altProp ) ;
52
37
const isVisible = isHiddenFromScreenReader ( type , node . attributes ) === false ;
53
38
54
- if ( Boolean ( value ) && typeof value === 'string' && isVisible ) {
39
+ if ( typeof value === 'string' && isVisible ) {
55
40
const hasRedundancy = REDUNDANT_WORDS
56
41
. some ( word => Boolean ( value . match ( new RegExp ( `(?!{)${ word } (?!})` , 'gi' ) ) ) ) ;
57
42
0 commit comments