diff --git a/__tests__/src/rules/img-redundant-alt-test.js b/__tests__/src/rules/img-redundant-alt-test.js index 4f862c473..e4ce2658f 100644 --- a/__tests__/src/rules/img-redundant-alt-test.js +++ b/__tests__/src/rules/img-redundant-alt-test.js @@ -8,6 +8,8 @@ // ----------------------------------------------------------------------------- import { RuleTester } from 'eslint'; +import semver from 'semver'; +import { version as eslintVersion } from 'eslint/package.json'; import parserOptionsMapper from '../../__util__/parserOptionsMapper'; import rule from '../../../src/rules/img-redundant-alt'; @@ -28,7 +30,7 @@ const expectedError = { }; ruleTester.run('img-redundant-alt', rule, { - valid: [ + valid: [].concat( { code: 'foo;' }, { code: 'picture of me taking a photo of an image' }, { code: 'photo of image' }, @@ -52,11 +54,16 @@ ruleTester.run('img-redundant-alt', rule, { { code: '{function(e){}}' }, { code: 'Doing cool things.' }, { code: 'test' }, - { code: '{imageAlt}' }, { code: '' }, + { code: '{imageAlt}' }, + { code: '{imageAlt.name}' }, + semver.satisfies(eslintVersion, '>= 6') ? [ + { code: '{imageAlt?.name}', parserOptions: { ecmaVersion: 2020 } }, + { code: 'Doing cool things', parserOptions: { ecmaVersion: 2020 } }, + ] : [], { code: 'Photography;' }, { code: 'ImageMagick;' }, - ].map(parserOptionsMapper), + ).map(parserOptionsMapper), invalid: [ { code: 'Photo of friend.;', errors: [expectedError] }, { code: 'Picture of friend.;', errors: [expectedError] }, diff --git a/package.json b/package.json index 177e34054..55ab2c7dc 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,8 @@ "has": "^1.0.3", "jsx-ast-utils": "^3.2.1", "language-tags": "^1.0.5", - "minimatch": "^3.0.5" + "minimatch": "^3.0.5", + "semver": "^6.0.0" }, "peerDependencies": { "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"