From ce4d57f853ce7f71bd31edaa524eeb3ff1d27cf1 Mon Sep 17 00:00:00 2001
From: Ross Rosales <52366381+ROSSROSALES@users.noreply.github.com>
Date: Tue, 11 Oct 2022 19:24:16 +0000
Subject: [PATCH] [Tests] migrate helper parsers function from
`eslint-plugin-react`
Co-authored-by: Ross Rosales <52366381+ROSSROSALES@users.noreply.github.com>
Co-authored-by: Jordan Harband
---
.../__util__/helpers/getESLintCoreRule.js | 9 +
__tests__/__util__/helpers/parsers.js | 186 ++++++++++++++++++
__tests__/src/rules/accessible-emoji-test.js | 9 +-
__tests__/src/rules/alt-text-test.js | 29 ++-
.../src/rules/anchor-ambiguous-text-test.js | 9 +-
.../src/rules/anchor-has-content-test.js | 9 +-
__tests__/src/rules/anchor-is-valid-test.js | 129 ++++++------
...aria-activedescendant-has-tabindex-test.js | 9 +-
__tests__/src/rules/aria-props-test.js | 9 +-
__tests__/src/rules/aria-proptypes-test.js | 25 +--
__tests__/src/rules/aria-role-test.js | 9 +-
.../rules/aria-unsupported-elements-test.js | 5 +-
.../src/rules/autocomplete-valid-test.js | 9 +-
.../click-events-have-key-events-test.js | 9 +-
.../control-has-associated-label-test.js | 25 +--
.../src/rules/heading-has-content-test.js | 9 +-
__tests__/src/rules/html-has-lang-test.js | 9 +-
__tests__/src/rules/iframe-has-title-test.js | 9 +-
__tests__/src/rules/img-redundant-alt-test.js | 9 +-
.../rules/interactive-supports-focus-test.js | 17 +-
.../label-has-associated-control-test.js | 33 ++--
__tests__/src/rules/label-has-for-test.js | 9 +-
__tests__/src/rules/lang-test.js | 9 +-
__tests__/src/rules/media-has-caption-test.js | 9 +-
.../mouse-events-have-key-events-test.js | 9 +-
__tests__/src/rules/no-access-key-test.js | 9 +-
.../rules/no-aria-hidden-on-focusable-test.js | 10 +-
__tests__/src/rules/no-autofocus-test.js | 9 +-
.../src/rules/no-distracting-elements-test.js | 9 +-
...ive-element-to-noninteractive-role-test.js | 17 +-
...oninteractive-element-interactions-test.js | 17 +-
...active-element-to-interactive-role-test.js | 17 +-
.../rules/no-noninteractive-tabindex-test.js | 17 +-
__tests__/src/rules/no-onchange-test.js | 9 +-
.../src/rules/no-redundant-roles-test.js | 27 +--
.../no-static-element-interactions-test.js | 17 +-
.../src/rules/prefer-tag-over-role-test.js | 9 +-
.../role-has-required-aria-props-test.js | 9 +-
.../rules/role-supports-aria-props-test.js | 9 +-
__tests__/src/rules/scope-test.js | 9 +-
.../src/rules/tabindex-no-positive-test.js | 9 +-
scripts/boilerplate/test.js | 9 +-
42 files changed, 534 insertions(+), 280 deletions(-)
create mode 100644 __tests__/__util__/helpers/getESLintCoreRule.js
create mode 100644 __tests__/__util__/helpers/parsers.js
diff --git a/__tests__/__util__/helpers/getESLintCoreRule.js b/__tests__/__util__/helpers/getESLintCoreRule.js
new file mode 100644
index 000000000..ee04494f0
--- /dev/null
+++ b/__tests__/__util__/helpers/getESLintCoreRule.js
@@ -0,0 +1,9 @@
+import { version } from 'eslint/package.json';
+import semver from 'semver';
+
+const isESLintV8 = semver.major(version) >= 8;
+
+// eslint-disable-next-line global-require, import/no-dynamic-require, import/no-unresolved
+const getESLintCoreRule = (ruleId) => (isESLintV8 ? require('eslint/use-at-your-own-risk').builtinRules.get(ruleId) : require(`eslint/lib/rules/${ruleId}`));
+
+export default getESLintCoreRule;
diff --git a/__tests__/__util__/helpers/parsers.js b/__tests__/__util__/helpers/parsers.js
new file mode 100644
index 000000000..fc75cf337
--- /dev/null
+++ b/__tests__/__util__/helpers/parsers.js
@@ -0,0 +1,186 @@
+import path from 'path';
+import semver from 'semver';
+import entries from 'object.entries';
+import { version } from 'eslint/package.json';
+import flatMap from 'array.prototype.flatmap';
+
+let tsParserVersion;
+try {
+ // eslint-disable-next-line import/no-unresolved, global-require
+ tsParserVersion = require('@typescript-eslint/parser/package.json').version;
+} catch (e) { /**/ }
+
+const disableNewTS = semver.satisfies(tsParserVersion, '>= 4.1') // this rule is not useful on v4.1+ of the TS parser
+ ? (x) => ({ ...x, features: [].concat(x.features, 'no-ts-new') })
+ : (x) => x;
+
+function minEcmaVersion(features, parserOptions) {
+ const minEcmaVersionForFeatures = {
+ 'class fields': 2022,
+ 'optional chaining': 2020,
+ 'nullish coalescing': 2020,
+ };
+ const result = Math.max(
+ ...[].concat(
+ (parserOptions && parserOptions.ecmaVersion) || [],
+ flatMap(entries(minEcmaVersionForFeatures), (entry) => {
+ const f = entry[0];
+ const y = entry[1];
+ return features.has(f) ? y : [];
+ }),
+ ).map((y) => (y > 5 && y < 2015 ? y + 2009 : y)), // normalize editions to years
+ );
+ return Number.isFinite(result) ? result : undefined;
+}
+
+const NODE_MODULES = '../../node_modules';
+
+const parsers = {
+ BABEL_ESLINT: path.join(__dirname, NODE_MODULES, 'babel-eslint'),
+ '@BABEL_ESLINT': path.join(__dirname, NODE_MODULES, '@babel/eslint-parser'),
+ TYPESCRIPT_ESLINT: path.join(__dirname, NODE_MODULES, 'typescript-eslint-parser'),
+ '@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser'),
+ disableNewTS,
+ babelParserOptions: function parserOptions(test, features) {
+ return {
+ ...test.parserOptions,
+ requireConfigFile: false,
+ babelOptions: {
+ presets: [
+ '@babel/preset-react',
+ ],
+ plugins: [
+ '@babel/plugin-syntax-do-expressions',
+ '@babel/plugin-syntax-function-bind',
+ ['@babel/plugin-syntax-decorators', { legacy: true }],
+ ],
+ parserOpts: {
+ allowSuperOutsideMethod: false,
+ allowReturnOutsideFunction: false,
+ },
+ },
+ ecmaFeatures: {
+
+ ...test.parserOptions && test.parserOptions.ecmaFeatures,
+ jsx: true,
+ modules: true,
+ legacyDecorators: features.has('decorators'),
+ },
+ };
+ },
+ all: function all(tests) {
+ const t = flatMap(tests, (test) => {
+ /* eslint no-param-reassign: 0 */
+ if (typeof test === 'string') {
+ test = { code: test };
+ }
+ if ('parser' in test) {
+ delete test.features;
+ return test;
+ }
+ const features = new Set([].concat(test.features || []));
+ delete test.features;
+
+ const es = minEcmaVersion(features, test.parserOptions);
+
+ function addComment(testObject, parser) {
+ const extras = [].concat(
+ `features: [${Array.from(features).join(',')}]`,
+ `parser: ${parser}`,
+ testObject.parserOptions ? `parserOptions: ${JSON.stringify(testObject.parserOptions)}` : [],
+ testObject.options ? `options: ${JSON.stringify(testObject.options)}` : [],
+ testObject.settings ? `settings: ${JSON.stringify(testObject.settings)}` : [],
+ );
+
+ const extraComment = `\n// ${extras.join(', ')}`;
+
+ // Augment expected fix code output with extraComment
+ const nextCode = { code: testObject.code + extraComment };
+ const nextOutput = testObject.output && { output: testObject.output + extraComment };
+
+ // Augment expected suggestion outputs with extraComment
+ // `errors` may be a number (expected number of errors) or an array of
+ // error objects.
+ const nextErrors = testObject.errors
+ && typeof testObject.errors !== 'number'
+ && {
+ errors: testObject.errors.map(
+ (errorObject) => {
+ const nextSuggestions = errorObject.suggestions && {
+ suggestions: errorObject.suggestions.map((suggestion) => ({ ...suggestion, output: suggestion.output + extraComment })),
+ };
+
+ return { ...errorObject, ...nextSuggestions };
+ },
+ ),
+ };
+
+ return {
+
+ ...testObject,
+ ...nextCode,
+ ...nextOutput,
+ ...nextErrors,
+ };
+ }
+
+ const skipBase = (features.has('class fields') && semver.satisfies(version, '< 8'))
+ || (es >= 2020 && semver.satisfies(version, '< 6'))
+ || features.has('no-default')
+ || features.has('bind operator')
+ || features.has('do expressions')
+ || features.has('decorators')
+ || features.has('flow')
+ || features.has('ts')
+ || features.has('types')
+ || (features.has('fragment') && semver.satisfies(version, '< 5'));
+
+ const skipBabel = features.has('no-babel');
+ const skipOldBabel = skipBabel
+ || features.has('no-babel-old')
+ || features.has('optional chaining')
+ || semver.satisfies(version, '>= 8');
+ const skipNewBabel = skipBabel
+ || features.has('no-babel-new')
+ || !semver.satisfies(version, '^7.5.0') // require('@babel/eslint-parser/package.json').peerDependencies.eslint
+ || features.has('flow')
+ || features.has('types')
+ || features.has('ts');
+ const skipTS = semver.satisfies(version, '<= 5') // TODO: make these pass on eslint 5
+ || features.has('no-ts')
+ || features.has('flow')
+ || features.has('jsx namespace')
+ || features.has('bind operator')
+ || features.has('do expressions');
+ const tsOld = !skipTS && !features.has('no-ts-old');
+ const tsNew = !skipTS && !features.has('no-ts-new');
+
+ return [].concat(
+ skipBase ? [] : addComment(
+ {
+ ...test,
+ ...typeof es === 'number' && {
+ parserOptions: { ...test.parserOptions, ecmaVersion: es },
+ },
+ },
+ 'default',
+ ),
+ skipOldBabel ? [] : addComment({
+ ...test,
+ parser: parsers.BABEL_ESLINT,
+ parserOptions: parsers.babelParserOptions(test, features),
+ }, 'babel-eslint'),
+ skipNewBabel ? [] : addComment({
+ ...test,
+ parser: parsers['@BABEL_ESLINT'],
+ parserOptions: parsers.babelParserOptions(test, features),
+ }, '@babel/eslint-parser'),
+ tsOld ? addComment({ ...test, parser: parsers.TYPESCRIPT_ESLINT }, 'typescript-eslint') : [],
+ tsNew ? addComment({ ...test, parser: parsers['@TYPESCRIPT_ESLINT'] }, '@typescript-eslint/parser') : [],
+ );
+ });
+ return t;
+ },
+};
+
+export default parsers;
diff --git a/__tests__/src/rules/accessible-emoji-test.js b/__tests__/src/rules/accessible-emoji-test.js
index dc3d19683..a1d21f461 100644
--- a/__tests__/src/rules/accessible-emoji-test.js
+++ b/__tests__/src/rules/accessible-emoji-test.js
@@ -10,6 +10,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import rule from '../../../src/rules/accessible-emoji';
+import parsers from '../../__util__/helpers/parsers';
// -----------------------------------------------------------------------------
// Tests
@@ -23,7 +24,7 @@ const expectedError = {
};
ruleTester.run('accessible-emoji', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: ';' },
{ code: '' },
{ code: 'No emoji here!' },
@@ -42,8 +43,8 @@ ruleTester.run('accessible-emoji', rule, {
code: '๐ผ',
settings: { 'jsx-a11y': { components: { CustomInput: 'input' } } },
},
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '๐ผ', errors: [expectedError] },
{ code: 'foo๐ผbar', errors: [expectedError] },
{ code: 'foo ๐ผ bar', errors: [expectedError] },
@@ -52,5 +53,5 @@ ruleTester.run('accessible-emoji', rule, {
{ code: '๐ผ', errors: [expectedError] },
{ code: '๐ผ', errors: [expectedError] },
{ code: '๐ผ', errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/alt-text-test.js b/__tests__/src/rules/alt-text-test.js
index bd2463d73..07b2c8259 100644
--- a/__tests__/src/rules/alt-text-test.js
+++ b/__tests__/src/rules/alt-text-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/alt-text';
// -----------------------------------------------------------------------------
@@ -28,19 +29,29 @@ Use alt="" for presentational images.`,
type: 'JSXOpeningElement',
});
-const ariaLabelValueError = 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.';
-const ariaLabelledbyValueError = 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.';
+const ariaLabelValueError = {
+ message: 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.',
+};
+const ariaLabelledbyValueError = {
+ message: 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.',
+};
const preferAltError = () => ({
message: 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.',
type: 'JSXOpeningElement',
});
-const objectError = 'Embedded ', errors: [expectedError] },
{ code: '', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '', settings: componentsSettings, errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/media-has-caption-test.js b/__tests__/src/rules/media-has-caption-test.js
index 23d56194d..ab08eeae6 100644
--- a/__tests__/src/rules/media-has-caption-test.js
+++ b/__tests__/src/rules/media-has-caption-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/media-has-caption';
// -----------------------------------------------------------------------------
@@ -41,7 +42,7 @@ const componentsSettings = {
};
ruleTester.run('media-has-caption', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: ';' },
{ code: ';' },
{ code: '' },
@@ -143,8 +144,8 @@ ruleTester.run('media-has-caption', rule, {
code: '',
settings: componentsSettings,
},
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '', errors: [expectedError] },
{
code: '',
@@ -205,5 +206,5 @@ ruleTester.run('media-has-caption', rule, {
settings: componentsSettings,
errors: [expectedError],
},
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/mouse-events-have-key-events-test.js b/__tests__/src/rules/mouse-events-have-key-events-test.js
index 638c9a51b..e7a7e9bb2 100644
--- a/__tests__/src/rules/mouse-events-have-key-events-test.js
+++ b/__tests__/src/rules/mouse-events-have-key-events-test.js
@@ -10,6 +10,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/mouse-events-have-key-events';
// -----------------------------------------------------------------------------
@@ -36,7 +37,7 @@ const pointerLeaveError = {
};
ruleTester.run('mouse-events-have-key-events', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: ' void 0} onFocus={() => void 0} />;' },
{
code: '
void 0} onFocus={() => void 0} {...props} />;',
@@ -94,8 +95,8 @@ ruleTester.run('mouse-events-have-key-events', rule, {
code: '
{}} />',
options: [{ hoverOutHandlers: ['onPointerLeave'] }],
},
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '
void 0} />;', errors: [mouseOverError] },
{ code: '
void 0} />', errors: [mouseOutError] },
{
@@ -149,5 +150,5 @@ ruleTester.run('mouse-events-have-key-events', rule, {
options: [{ hoverOutHandlers: ['onPointerLeave'] }],
errors: [pointerLeaveError],
},
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-access-key-test.js b/__tests__/src/rules/no-access-key-test.js
index 7987d054b..fc9943853 100644
--- a/__tests__/src/rules/no-access-key-test.js
+++ b/__tests__/src/rules/no-access-key-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-access-key';
// -----------------------------------------------------------------------------
@@ -23,12 +24,12 @@ const expectedError = {
};
ruleTester.run('no-access-key', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: '
;' },
{ code: '
' },
{ code: '
' },
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
@@ -43,5 +44,5 @@ ruleTester.run('no-access-key', rule, {
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-aria-hidden-on-focusable-test.js b/__tests__/src/rules/no-aria-hidden-on-focusable-test.js
index 6d908b0aa..b341a2cbb 100644
--- a/__tests__/src/rules/no-aria-hidden-on-focusable-test.js
+++ b/__tests__/src/rules/no-aria-hidden-on-focusable-test.js
@@ -9,7 +9,9 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-aria-hidden-on-focusable';
+
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
@@ -22,7 +24,7 @@ const expectedError = {
};
ruleTester.run('no-aria-hidden-on-focusable', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: '
;' },
{ code: '
void 0} aria-hidden="true" />;' },
{ code: '
' },
@@ -30,13 +32,13 @@ ruleTester.run('no-aria-hidden-on-focusable', rule, {
{ code: '
' },
{ code: '
' },
{ code: '
' },
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '
;', errors: [expectedError] },
{ code: '
;', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
text
;', errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-autofocus-test.js b/__tests__/src/rules/no-autofocus-test.js
index ce762765f..13bddc724 100644
--- a/__tests__/src/rules/no-autofocus-test.js
+++ b/__tests__/src/rules/no-autofocus-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-autofocus';
// -----------------------------------------------------------------------------
@@ -37,7 +38,7 @@ const componentsSettings = {
};
ruleTester.run('no-autofocus', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: '
;' },
{ code: '
;' },
{ code: '
;' },
@@ -46,8 +47,8 @@ ruleTester.run('no-autofocus', rule, {
{ code: '
', options: ignoreNonDOMSchema },
{ code: '
', settings: componentsSettings },
{ code: '
', options: ignoreNonDOMSchema, settings: componentsSettings },
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
{ code: '
', errors: [expectedError] },
@@ -63,5 +64,5 @@ ruleTester.run('no-autofocus', rule, {
options: ignoreNonDOMSchema,
settings: componentsSettings,
},
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-distracting-elements-test.js b/__tests__/src/rules/no-distracting-elements-test.js
index 5e77ae03c..16a7b1b31 100644
--- a/__tests__/src/rules/no-distracting-elements-test.js
+++ b/__tests__/src/rules/no-distracting-elements-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-distracting-elements';
// -----------------------------------------------------------------------------
@@ -31,14 +32,14 @@ const componentsSettings = {
};
ruleTester.run('no-marquee', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: '
;' },
{ code: '
' },
{ code: '
' },
{ code: '
' },
{ code: '
' },
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
{ code: '
', errors: [expectedError('marquee')] },
{ code: '
', errors: [expectedError('marquee')] },
{ code: '
', errors: [expectedError('marquee')] },
@@ -46,5 +47,5 @@ ruleTester.run('no-marquee', rule, {
{ code: '
', errors: [expectedError('blink')] },
{ code: '
', errors: [expectedError('blink')] },
{ code: '
', settings: componentsSettings, errors: [expectedError('blink')] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-interactive-element-to-noninteractive-role-test.js b/__tests__/src/rules/no-interactive-element-to-noninteractive-role-test.js
index 49384d54b..9edb85e52 100644
--- a/__tests__/src/rules/no-interactive-element-to-noninteractive-role-test.js
+++ b/__tests__/src/rules/no-interactive-element-to-noninteractive-role-test.js
@@ -11,6 +11,7 @@
import { RuleTester } from 'eslint';
import { configs } from '../../../src/index';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-interactive-element-to-noninteractive-role';
import ruleOptionsMapperFactory from '../../__util__/ruleOptionsMapperFactory';
@@ -378,28 +379,28 @@ const neverValid = [
const recommendedOptions = (configs.recommended.rules[ruleName][1] || {});
ruleTester.run(`${ruleName}:recommended`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
{ code: '
|
;' },
{ code: '
;' },
{ code: '
;' },
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
- invalid: [
+ invalid: parsers.all([].concat(
...neverValid,
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
});
ruleTester.run(`${ruleName}:strict`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
...neverValid,
{ code: '
|
;', errors: [expectedError] },
{ code: '
;', errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-noninteractive-element-interactions-test.js b/__tests__/src/rules/no-noninteractive-element-interactions-test.js
index c74abae18..d13c136d7 100644
--- a/__tests__/src/rules/no-noninteractive-element-interactions-test.js
+++ b/__tests__/src/rules/no-noninteractive-element-interactions-test.js
@@ -10,6 +10,7 @@
import { RuleTester } from 'eslint';
import { configs } from '../../../src/index';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-noninteractive-element-interactions';
import ruleOptionsMapperFactory from '../../__util__/ruleOptionsMapperFactory';
@@ -396,7 +397,7 @@ const neverValid = [
const recommendedOptions = configs.recommended.rules[`jsx-a11y/${ruleName}`][1] || {};
ruleTester.run(`${ruleName}:recommended`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
// All the possible handlers
{ code: '
{}} />;' },
@@ -459,24 +460,24 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
{ code: '
{}} />;' },
{ code: '
{}} />;' },
{ code: '
{}} />;' },
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
- invalid: [
+ invalid: parsers.all([].concat(
...neverValid,
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
});
const strictOptions = configs.strict.rules[`jsx-a11y/${ruleName}`][1] || {};
ruleTester.run(`${ruleName}:strict`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
- ]
+ ))
.map(ruleOptionsMapperFactory(strictOptions))
.map(parserOptionsMapper),
- invalid: [
+ invalid: parsers.all([].concat(
...neverValid,
// All the possible handlers
{ code: '
{}} />;', errors: [expectedError] },
@@ -497,7 +498,7 @@ ruleTester.run(`${ruleName}:strict`, rule, {
{ code: '
{}} />;', errors: [expectedError] },
{ code: '
{}} />;', errors: [expectedError] },
{ code: '
{}} />;', errors: [expectedError] },
- ]
+ ))
.map(ruleOptionsMapperFactory(strictOptions))
.map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-noninteractive-element-to-interactive-role-test.js b/__tests__/src/rules/no-noninteractive-element-to-interactive-role-test.js
index 2f25c95ab..da1f4f802 100644
--- a/__tests__/src/rules/no-noninteractive-element-to-interactive-role-test.js
+++ b/__tests__/src/rules/no-noninteractive-element-to-interactive-role-test.js
@@ -12,6 +12,7 @@
import { RuleTester } from 'eslint';
import { configs } from '../../../src/index';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-noninteractive-element-to-interactive-role';
import ruleOptionsMapperFactory from '../../__util__/ruleOptionsMapperFactory';
@@ -440,7 +441,7 @@ const neverValid = [
const recommendedOptions = (configs.recommended.rules[ruleName][1] || {});
ruleTester.run(`${ruleName}:recommended`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
{ code: '
;' },
{ code: '
;' },
@@ -461,21 +462,21 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
{ code: '
;' },
{ code: '
;' },
{ code: '
;' },
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
- invalid: [
+ invalid: parsers.all([].concat(
...neverValid,
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
});
ruleTester.run(`${ruleName}:strict`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
...neverValid,
{ code: '
;', errors: [expectedError] },
{ code: '
;', errors: [expectedError] },
@@ -493,5 +494,5 @@ ruleTester.run(`${ruleName}:strict`, rule, {
{ code: '
;', errors: [expectedError] },
{ code: '
;', errors: [expectedError] },
{ code: '
;', errors: [expectedError] },
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-noninteractive-tabindex-test.js b/__tests__/src/rules/no-noninteractive-tabindex-test.js
index 2c8f1ac4b..c832f3778 100644
--- a/__tests__/src/rules/no-noninteractive-tabindex-test.js
+++ b/__tests__/src/rules/no-noninteractive-tabindex-test.js
@@ -10,6 +10,7 @@
import { RuleTester } from 'eslint';
import { configs } from '../../../src/index';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-noninteractive-tabindex';
import ruleOptionsMapperFactory from '../../__util__/ruleOptionsMapperFactory';
@@ -62,7 +63,7 @@ const recommendedOptions = (
);
ruleTester.run(`${ruleName}:recommended`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
{ code: '
' },
// Expressions should pass in recommended mode
@@ -87,21 +88,21 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
options: [{ allowExpressionValues: true }],
errors: [expectedError],
},
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
- invalid: [
+ invalid: parsers.all([].concat(
...neverValid,
- ]
+ ))
.map(ruleOptionsMapperFactory(recommendedOptions))
.map(parserOptionsMapper),
});
ruleTester.run(`${ruleName}:strict`, rule, {
- valid: [
+ valid: parsers.all([].concat(
...alwaysValid,
- ].map(parserOptionsMapper),
- invalid: [
+ )).map(parserOptionsMapper),
+ invalid: parsers.all([].concat(
...neverValid,
{ code: '
', errors: [expectedError] },
// Expressions should fail in strict mode
@@ -118,5 +119,5 @@ ruleTester.run(`${ruleName}:strict`, rule, {
options: [{ allowExpressionValues: false }],
errors: [expectedError],
},
- ].map(parserOptionsMapper),
+ )).map(parserOptionsMapper),
});
diff --git a/__tests__/src/rules/no-onchange-test.js b/__tests__/src/rules/no-onchange-test.js
index a29170b81..f45734436 100644
--- a/__tests__/src/rules/no-onchange-test.js
+++ b/__tests__/src/rules/no-onchange-test.js
@@ -9,6 +9,7 @@
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
+import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-onchange';
// -----------------------------------------------------------------------------
@@ -32,7 +33,7 @@ const componentsSettings = {
};
ruleTester.run('no-onchange', rule, {
- valid: [
+ valid: parsers.all([].concat(
{ code: '