Skip to content

remove polyfills #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __mocks__/genInteractives.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import type { JSXElementMockType } from './JSXElementMock';

const { fromEntries } = Object;

const domElements = [...dom.keys()];
const roleNames = [...roles.keys()];
const domElements = dom.keys();
const roleNames = roles.keys();

const interactiveElementsMap = {
a: [{ prop: 'href', value: '#' }],
Expand Down Expand Up @@ -170,7 +170,7 @@ export function genInteractiveElements(): Array<JSXElementMockType> {
if (bracketIndex > -1) {
name = elementSymbol.slice(0, bracketIndex);
}
const attributes = interactiveElementsMap[elementSymbol].map(({ prop, value }) => JSXAttributeMock(prop, value));
const attributes = interactiveElementsMap[(elementSymbol: any)].map(({ prop, value }) => JSXAttributeMock(prop, value));
return JSXElementMock(name, attributes);
});
}
Expand Down
7 changes: 4 additions & 3 deletions __tests__/__util__/helpers/parsers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import semver from 'semver';
import { version } from 'eslint/package.json';
import flatMap from 'array.prototype.flatmap';

const { entries } = Object;

let tsParserVersion;
try {
Expand All @@ -22,7 +23,7 @@ function minEcmaVersion(features, parserOptions) {
const result = Math.max(
...[].concat(
(parserOptions && parserOptions.ecmaVersion) || [],
flatMap(Object.entries(minEcmaVersionForFeatures), (entry) => {
entries(minEcmaVersionForFeatures).flatMap((entry) => {
const f = entry[0];
const y = entry[1];
return features.has(f) ? y : [];
Expand Down Expand Up @@ -68,7 +69,7 @@ const parsers = {
};
},
all: function all(tests) {
const t = flatMap(tests, (test) => {
const t = tests.flatMap((test) => {
/* eslint no-param-reassign: 0 */
if (typeof test === 'string') {
test = { code: test };
Expand Down
4 changes: 1 addition & 3 deletions __tests__/__util__/ruleOptionsMapperFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @flow
*/

import flatMap from 'array.prototype.flatmap';

const { fromEntries, entries } = Object;

type ESLintTestRunnerTestCase = {
Expand All @@ -25,7 +23,7 @@ export default function ruleOptionsMapperFactory(ruleOptions: Array<mixed> = [])
code,
errors,
// Flatten the array of objects in an array of one object.
options: [fromEntries(flatMap((options || []).concat(ruleOptions), (item) => entries(item)))],
options: [fromEntries((options || []).concat(ruleOptions).flatMap((item) => entries((item: any))))],
parserOptions,
settings,
};
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import getSuggestion from '../../../src/util/getSuggestion';
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ariaAttributes = [...aria.keys()];
const ariaAttributes = aria.keys();

const errorMessage = (name) => {
const suggestions = getSuggestion(name, ariaAttributes);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-role-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const errorMessage = {
type: 'JSXAttribute',
};

const roleKeys = [...roles.keys()];
const roleKeys = roles.keys();

const validRoles = roleKeys.filter((role) => roles.get(role).abstract === false);
const invalidRoles = roleKeys.filter((role) => roles.get(role).abstract === true);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/rules/aria-unsupported-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const errorMessage = (invalidProp) => ({
type: 'JSXOpeningElement',
});

const domElements = [...dom.keys()];
const domElements = dom.keys();
// Generate valid test cases
const roleValidityTests = domElements.map((element) => {
const isReserved = dom.get(element).reserved || false;
Expand Down
1 change: 1 addition & 0 deletions flow/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export type ESLintReport = {
node: any,
message: string,
data?: any
};

export type ESLintSettings = {
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"eslint-plugin-flowtype": "^5.8.0 || ^8.0.3",
"eslint-plugin-import": "^2.31.0",
"estraverse": "^5.3.0",
"flow-bin": "^0.147.0",
"flow-bin": "^0.250.0",
"in-publish": "^2.0.1",
"jackspeak": "=2.1.1",
"jscodeshift": "^17.0.0",
Expand All @@ -74,12 +74,10 @@
"license": "MIT",
"dependencies": {
"aria-query": "^5.3.2",
"array.prototype.flatmap": "^1.3.2",
"ast-types-flow": "^0.0.8",
"axe-core": "^4.10.0",
"axobject-query": "^4.1.0",
"damerau-levenshtein": "^1.0.8",
"hasown": "^2.0.2",
"jsx-ast-utils": "^3.3.5",
"language-tags": "^1.0.9",
"minimatch": "^10.0.1",
Expand Down
7 changes: 2 additions & 5 deletions src/rules/alt-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getPropValue,
getLiteralPropValue,
} from 'jsx-ast-utils';
import flatMap from 'array.prototype.flatmap';

import { generateObjSchema, arraySchema } from '../util/schemas';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -222,10 +221,8 @@ export default {
// Elements to validate for alt text.
const elementOptions = options.elements || DEFAULT_ELEMENTS;
// Get custom components for just the elements that will be tested.
const customComponents = flatMap(
elementOptions,
(element) => options[element],
);
const customComponents = elementOptions.flatMap((element) => options[element]);

const typesToValidate = new Set(
[].concat(
customComponents,
Expand Down
3 changes: 1 addition & 2 deletions src/rules/anchor-ambiguous-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------

import type { ESLintConfig, ESLintContext } from '../../flow/eslint';
import { arraySchema, generateObjSchema } from '../util/schemas';
import getAccessibleChildText from '../util/getAccessibleChildText';
Expand Down Expand Up @@ -44,7 +43,7 @@ export default ({
const ambiguousWords = new Set(words);

return {
JSXOpeningElement: (node) => {
JSXOpeningElement: (node: any) => {
const nodeType = elementType(node);

// Only check anchor elements and custom types.
Expand Down
2 changes: 1 addition & 1 deletion src/rules/anchor-is-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default ({

// Create active aspect flag object. Failing checks will only report
// if the related flag is set to true.
const activeAspects = {};
const activeAspects: Object = {};
allAspects.forEach((aspect) => {
activeAspects[aspect] = aspects.indexOf(aspect) !== -1;
});
Expand Down
6 changes: 5 additions & 1 deletion src/rules/control-has-associated-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import type { JSXElement } from 'ast-types-flow';
import { generateObjSchema, arraySchema } from '../util/schemas';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import type {
ESLintConfig,
ESLintContext,
ESLintVisitorSelectorConfig,
} from '../../flow/eslint';
import getElementType from '../util/getElementType';
import isDOMElement from '../util/isDOMElement';
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
Expand Down
2 changes: 1 addition & 1 deletion src/rules/label-has-associated-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const schema = generateObjSchema({
},
});

function validateID(node, context) {
function validateID(node: Object, context: Object) {
const { settings } = context;
const htmlForAttributes = settings['jsx-a11y']?.attributes?.for ?? ['htmlFor'];

Expand Down
7 changes: 3 additions & 4 deletions src/rules/media-has-caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import type { JSXElement, JSXOpeningElement, Node } from 'ast-types-flow';
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
import flatMap from 'array.prototype.flatmap';

import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import { generateObjSchema, arraySchema } from '../util/schemas';
Expand All @@ -26,14 +25,14 @@ const schema = generateObjSchema({
track: arraySchema,
});

const isMediaType = (context, type) => {
const isMediaType = (context: Object, type: string) => {
const options = context.options[0] || {};
return MEDIA_TYPES
.concat(flatMap(MEDIA_TYPES, (mediaType) => options[mediaType]))
.concat(MEDIA_TYPES.flatMap((mediaType) => options[mediaType]))
.some((typeToCheck) => typeToCheck === type);
};

const isTrackType = (context, type) => {
const isTrackType = (context: Object, type: string) => {
const options = context.options[0] || {};
return ['track'].concat(options.track || []).some((typeToCheck) => typeToCheck === type);
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/mouse-events-have-key-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default ({
},

create: (context: ESLintContext) => ({
JSXOpeningElement: (node) => {
JSXOpeningElement: (node: Object) => {
const { name } = node.name;

if (!dom.get(name)) {
Expand Down
3 changes: 2 additions & 1 deletion src/rules/no-interactive-element-to-noninteractive-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import {
propName,
} from 'jsx-ast-utils';
import type { JSXIdentifier } from 'ast-types-flow';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
import getElementType from '../util/getElementType';
import isInteractiveElement from '../util/isInteractiveElement';
import isNonInteractiveRole from '../util/isNonInteractiveRole';
import isPresentationRole from '../util/isPresentationRole';

const { hasOwn } = Object;

const errorMessage = 'Interactive elements should not be assigned non-interactive roles.';

export default ({
Expand Down
3 changes: 2 additions & 1 deletion src/rules/no-noninteractive-element-interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
propName,
} from 'jsx-ast-utils';
import type { JSXOpeningElement } from 'ast-types-flow';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import { arraySchema, generateObjSchema } from '../util/schemas';
import getElementType from '../util/getElementType';
Expand All @@ -29,6 +28,8 @@ import isNonInteractiveElement from '../util/isNonInteractiveElement';
import isNonInteractiveRole from '../util/isNonInteractiveRole';
import isPresentationRole from '../util/isPresentationRole';

const { hasOwn } = Object;

const errorMessage = 'Non-interactive elements should not be assigned mouse or keyboard event listeners.';

const defaultInteractiveProps = [].concat(
Expand Down
3 changes: 2 additions & 1 deletion src/rules/no-noninteractive-element-to-interactive-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
propName,
} from 'jsx-ast-utils';
import type { JSXIdentifier } from 'ast-types-flow';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
import getElementType from '../util/getElementType';
import getExplicitRole from '../util/getExplicitRole';
import isNonInteractiveElement from '../util/isNonInteractiveElement';
import isInteractiveRole from '../util/isInteractiveRole';

const { hasOwn } = Object;

const errorMessage = 'Non-interactive elements should not be assigned interactive roles.';

export default ({
Expand Down
7 changes: 4 additions & 3 deletions src/rules/no-redundant-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
// Rule Definition
// ----------------------------------------------------------------------------

import hasOwn from 'hasown';
import type { JSXOpeningElement } from 'ast-types-flow';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import getElementType from '../util/getElementType';
import getExplicitRole from '../util/getExplicitRole';
import getImplicitRole from '../util/getImplicitRole';

const errorMessage = (element, implicitRole) => (
const { hasOwn } = Object;

const errorMessage = (element: string, implicitRole: string) => (
`The element ${element} has an implicit role of ${implicitRole}. Defining this explicitly is redundant and should be avoided.`
);

Expand Down Expand Up @@ -45,7 +46,7 @@ export default ({
const elementType = getElementType(context);
return {
JSXOpeningElement: (node: JSXOpeningElement) => {
const type = elementType(node);
const type: any = elementType(node);
const implicitRole = getImplicitRole(type, node.attributes);
const explicitRole = getExplicitRole(type, node.attributes);

Expand Down
4 changes: 3 additions & 1 deletion src/rules/role-has-required-aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import isSemanticRoleElement from '../util/isSemanticRoleElement';

const schema = generateObjSchema();

const roleKeys = roles.keys();

export default {
meta: {
docs: {
Expand Down Expand Up @@ -59,7 +61,7 @@ export default {

const normalizedValues = String(roleAttrValue).toLowerCase().split(' ');
const validRoles = normalizedValues
.filter((val) => [...roles.keys()].indexOf(val) > -1);
.filter((val) => roleKeys.indexOf(val) > -1);

// Check semantic DOM elements
// For example, <input type="checkbox" role="switch" />
Expand Down
3 changes: 2 additions & 1 deletion src/util/getElementType.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
*/

import type { JSXOpeningElement } from 'ast-types-flow';
import hasOwn from 'hasown';
import { elementType, getProp, getLiteralPropValue } from 'jsx-ast-utils';

import type { ESLintContext } from '../../flow/eslint';

const { hasOwn } = Object;

const getElementType = (context: ESLintContext): ((node: JSXOpeningElement) => string) => {
const { settings } = context;
const polymorphicPropName = settings['jsx-a11y']?.polymorphicPropName;
Expand Down
2 changes: 1 addition & 1 deletion src/util/getExplicitRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function getExplicitRole(
tag: string,
attributes: Array<Node>,
): ?string {
const explicitRole = (function toLowerCase(role) {
const explicitRole = (function toLowerCase(role: any) {
if (typeof role === 'string') {
return role.toLowerCase();
}
Expand Down
22 changes: 6 additions & 16 deletions src/util/isInteractiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {
AXObjects,
elementAXObjects,
} from 'axobject-query';
import flatMap from 'array.prototype.flatmap';

import attributesComparator from './attributesComparator';

const roleKeys = [...roles.keys()];
const roleKeys = roles.keys();
const elementRoleEntries = [...elementRoles];

const nonInteractiveRoles = new Set(roleKeys
Expand Down Expand Up @@ -50,25 +49,16 @@ const interactiveRoles = new Set(roleKeys
'toolbar',
));

const interactiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []),
);
const interactiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.some((role): boolean => interactiveRoles.has(role)) ? [elementSchema] : []));

const nonInteractiveElementRoleSchemas = flatMap(
elementRoleEntries,
([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []),
);
const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap(([elementSchema, rolesArr]) => (rolesArr.every((role): boolean => nonInteractiveRoles.has(role)) ? [elementSchema] : []));

const interactiveAXObjects = new Set(AXObjects.keys().filter((name) => AXObjects.get(name).type === 'widget'));

const interactiveElementAXObjectSchemas = flatMap(
[...elementAXObjects],
([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []),
);
const interactiveElementAXObjectSchemas = [...elementAXObjects].flatMap(([elementSchema, AXObjectsArr]) => (AXObjectsArr.every((role): boolean => interactiveAXObjects.has(role)) ? [elementSchema] : []));

function checkIsInteractiveElement(tagName, attributes): boolean {
function elementSchemaMatcher(elementSchema) {
function checkIsInteractiveElement(tagName: string, attributes: Object): boolean {
function elementSchemaMatcher(elementSchema: Object) {
return (
tagName === elementSchema.name
&& attributesComparator(elementSchema.attributes, attributes)
Expand Down
Loading