Skip to content

Commit

Permalink
Remove audit role that depends on CJS package (#9293)
Browse files Browse the repository at this point in the history
* Remove audit role that depends on CJS package

* Adding changeset

---------

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
matthewp and natemoo-re authored Dec 4, 2023
1 parent e88f166 commit cf5fa43
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 69 deletions.
7 changes: 7 additions & 0 deletions .changeset/tender-eagles-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': patch
---

Removes the 'a11y-role-has-required-aria-props' audit rule

This audit rule depends on a CommonJS module. To prevent blocking the 4.0 release the rule is being removed temporarily.
1 change: 0 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"@types/babel__core": "^7.20.4",
"acorn": "^8.11.2",
"aria-query": "^5.3.0",
"axobject-query": "^4.0.0",
"boxen": "^7.1.1",
"chokidar": "^3.5.3",
"ci-info": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import type { ARIARoleDefinitionKey } from 'aria-query';
import { aria, roles } from 'aria-query';
import type { AuditRuleWithSelector } from './index.js';
// @ts-expect-error package does not provide types
import { AXObjectRoles, elementAXObjects } from 'axobject-query';

const a11y_required_attributes = {
a: ['href'],
Expand Down Expand Up @@ -437,32 +435,6 @@ export const a11y: AuditRuleWithSelector[] = [
'This will move elements out of the expected tab order, creating a confusing experience for keyboard users.',
selector: '[tabindex]:not([tabindex="-1"]):not([tabindex="0"])',
},
{
code: 'a11y-role-has-required-aria-props',
title: 'Missing attributes required for ARIA role',
message: (element) => {
const { __astro_role: role, __astro_missing_attributes: required } = element as any;
return `${
element.localName
} element is missing required attributes for its role (${role}): ${required.join(', ')}`;
},
selector: '*',
match(element) {
const role = getRole(element);
if (!role) return false;
if (is_semantic_role_element(role, element.localName, getAttributeObject(element))) {
return;
}
const { requiredProps } = roles.get(role)!;
const required_role_props = Object.keys(requiredProps);
const missingProps = required_role_props.filter((prop) => !element.hasAttribute(prop));
if (missingProps.length > 0) {
(element as any).__astro_role = role;
(element as any).__astro_missing_attributes = missingProps;
return true;
}
},
},
{
code: 'a11y-role-supports-aria-props',
title: 'Unsupported ARIA attribute',
Expand Down Expand Up @@ -595,34 +567,3 @@ function getAttributeObject(element: Element): Record<string, string> {
}
return obj;
}

/**
* @param {import('aria-query').ARIARoleDefinitionKey} role
* @param {string} tag_name
* @param {Map<string, import('#compiler').Attribute>} attribute_map
*/
function is_semantic_role_element(
role: string,
tag_name: string,
attributes: Record<string, string>
) {
for (const [schema, ax_object] of elementAXObjects.entries()) {
if (
schema.name === tag_name &&
(!schema.attributes ||
schema.attributes.every((attr: any) => attributes[attr.name] === attr.value))
) {
for (const name of ax_object) {
const axRoles = AXObjectRoles.get(name);
if (axRoles) {
for (const { name: _name } of axRoles) {
if (_name === role) {
return true;
}
}
}
}
}
}
return false;
}
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf5fa43

Please sign in to comment.