8
8
// -----------------------------------------------------------------------------
9
9
10
10
import { RuleTester } from 'eslint' ;
11
+ import semver from 'semver' ;
12
+ import { version as eslintVersion } from 'eslint/package.json' ;
11
13
import parserOptionsMapper from '../../__util__/parserOptionsMapper' ;
12
14
import rule from '../../../src/rules/img-redundant-alt' ;
13
15
@@ -28,7 +30,7 @@ const expectedError = {
28
30
} ;
29
31
30
32
ruleTester . run ( 'img-redundant-alt' , rule , {
31
- valid : [
33
+ valid : [ ] . concat (
32
34
{ code : '<img alt="foo" />;' } ,
33
35
{ code : '<img alt="picture of me taking a photo of an image" aria-hidden />' } ,
34
36
{ code : '<img aria-hidden alt="photo of image" />' } ,
@@ -52,11 +54,16 @@ ruleTester.run('img-redundant-alt', rule, {
52
54
{ code : '<img alt={function(e){}} />' } ,
53
55
{ code : '<img aria-hidden={false} alt="Doing cool things." />' } ,
54
56
{ code : '<UX.Layout>test</UX.Layout>' } ,
55
- { code : '<img alt={imageAlt} />' } ,
56
57
{ code : '<img alt />' } ,
58
+ { code : '<img alt={imageAlt} />' } ,
59
+ { code : '<img alt={imageAlt.name} />' } ,
60
+ semver . satisfies ( eslintVersion , '>= 6' ) ? [
61
+ { code : '<img alt={imageAlt?.name} />' , parserOptions : { ecmaVersion : 2020 } } ,
62
+ { code : '<img alt="Doing cool things" aria-hidden={foo?.bar}/>' , parserOptions : { ecmaVersion : 2020 } } ,
63
+ ] : [ ] ,
57
64
{ code : '<img alt="Photography" />;' } ,
58
65
{ code : '<img alt="ImageMagick" />;' } ,
59
- ] . map ( parserOptionsMapper ) ,
66
+ ) . map ( parserOptionsMapper ) ,
60
67
invalid : [
61
68
{ code : '<img alt="Photo of friend." />;' , errors : [ expectedError ] } ,
62
69
{ code : '<img alt="Picture of friend." />;' , errors : [ expectedError ] } ,
0 commit comments