Skip to content

Commit b180da7

Browse files
Copilotkoddsson
andauthored
Add id field to AccessibilityError and interpolate URLs (#199)
* Initial plan * Add id field to AccessibilityError interface and all rules Co-authored-by: koddsson <[email protected]> * Interpolate URLs and remove query parameters from all rules and tests Co-authored-by: koddsson <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: koddsson <[email protected]>
1 parent 5c60261 commit b180da7

File tree

109 files changed

+389
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+389
-269
lines changed

src/rules/accesskeys.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AccessibilityError } from "../scanner";
22

3+
const id = "accesskeys";
34
const text = "Ensures every accesskey attribute value is unique";
4-
const url =
5-
"https://dequeuniversity.com/rules/axe/4.4/accesskeys?application=RuleDescription";
5+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
66

77
export default function (element: Element): AccessibilityError[] {
88
const errors: AccessibilityError[] = [];
@@ -33,6 +33,7 @@ export default function (element: Element): AccessibilityError[] {
3333
if (elementsWithKey.length > 1) {
3434
for (const el of elementsWithKey) {
3535
errors.push({
36+
id,
3637
element: el,
3738
text,
3839
url,

src/rules/area-alt.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { AccessibilityError } from "../scanner";
22
import { querySelectorAll, labelledByIsValid } from "../utils";
33

4+
const id = "area-alt";
45
const text = "Elements must only use allowed ARIA attributes";
5-
const url =
6-
"https://dequeuniversity.com/rules/axe/4.4/area-alt?application=RuleDescription";
6+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
77

88
export function areaAlt(element_: Element): AccessibilityError[] {
99
const errors = [];
@@ -13,6 +13,7 @@ export function areaAlt(element_: Element): AccessibilityError[] {
1313
if (element.getAttribute("aria-label")) continue;
1414
if (labelledByIsValid(element)) continue;
1515
errors.push({
16+
id,
1617
element,
1718
text,
1819
url,

src/rules/aria-allowed-attr.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { querySelectorAll } from "../utils";
22
import { AccessibilityError } from "../scanner";
33

4+
const id = "aria-allowed-attr";
45
const text = "Elements must only use allowed ARIA attributes";
5-
const url =
6-
"https://dequeuniversity.com/rules/axe/4.4/aria-allowed-attr?application=RuleDescription";
6+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
77

88
// TODO: Fill out the rest of the mappings from https://www.w3.org/TR/html-aria/#docconformance
99
const ariaMappings: Record<string, string | undefined> = {
@@ -18,6 +18,7 @@ export function ariaAllowedAttr(element_: Element): AccessibilityError[] {
1818
if (element.getAttribute("role") === ariaMappings[element.tagName])
1919
continue;
2020
errors.push({
21+
id,
2122
element,
2223
text,
2324
url,

src/rules/aria-command-name.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { AccessibilityError } from "../scanner";
22
import { querySelectorAll, hasAccessibleText } from "../utils";
33

4+
const id = "aria-command-name";
45
const text = "ARIA button, link, and menuitem must have an accessible name";
5-
const url = "https://dequeuniversity.com/rules/axe/4.4/aria-command-name";
6+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
67

78
/*
89
<div role="link" id="al" aria-label="Name"></div>
@@ -27,7 +28,7 @@ export default function (el: Element): AccessibilityError[] {
2728

2829
for (const element of elements) {
2930
if (hasAccessibleText(element)) continue;
30-
errors.push({ element, text, url });
31+
errors.push({ id, element, text, url });
3132
}
3233
return errors;
3334
}

src/rules/aria-dialog-name.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { labelledByIsValid, querySelectorAll } from "../utils";
44
// Metadata
55
const id = "aria-dialog-name";
66
const text = "ARIA dialog and alertdialog nodes must have an accessible name";
7-
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`;
7+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
88

99
/**
1010
* Check if an element has an accessible name via aria-label, aria-labelledby, or title
@@ -43,6 +43,7 @@ export default function (element: Element): AccessibilityError[] {
4343
for (const el of elements) {
4444
if (!hasAccessibleName(el)) {
4545
errors.push({
46+
id,
4647
element: el,
4748
url,
4849
text,

src/rules/aria-hidden-body.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { AccessibilityError } from "../scanner";
22

3+
const id = "aria-hidden-body";
34
const text = 'aria-hidden="true" must not be present on the document <body>';
4-
const url =
5-
"https://dequeuniversity.com/rules/axe/4.4/aria-hidden-body?application=RuleDescription";
5+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
66

77
export function ariaHiddenBody(element_: Element): AccessibilityError[] {
88
const element = element_.ownerDocument.body;
99
if (element.getAttribute("aria-hidden") === "true") {
1010
return [
1111
{
12+
id,
1213
element,
1314
text,
1415
url,

src/rules/aria-hidden-focus.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { AccessibilityError } from "../scanner";
22
import { querySelectorAll, isVisible } from "../utils";
33

4+
const id = "aria-hidden-focus";
45
const text = "aria-hidden elements do not contain focusable elements";
5-
const url = "https://dequeuniversity.com/rules/axe/4.4/aria-hidden-focus";
6+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
67

78
const focusableSelector = [
89
"a[href]",
@@ -94,6 +95,7 @@ export default function ariaHiddenFocus(
9495

9596
if (hasOffendingFocusable) {
9697
errors.push({
98+
id,
9799
element: hiddenElement,
98100
text,
99101
url,

src/rules/aria-input-field-name.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { labelledByIsValid, querySelectorAll } from "../utils";
44
// Metadata
55
const id = "aria-input-field-name";
66
const text = "ARIA input fields must have an accessible name";
7-
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`;
7+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
88

99
// ARIA roles that are considered input fields
1010
const inputFieldRoles = [
@@ -54,6 +54,7 @@ export default function (element: Element): AccessibilityError[] {
5454
for (const el of elements) {
5555
if (!hasAccessibleName(el)) {
5656
errors.push({
57+
id,
5758
element: el,
5859
url,
5960
text,

src/rules/aria-meter-name.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { labelledByIsValid, querySelectorAll } from "../utils";
44
// Metadata
55
const id = "aria-meter-name";
66
const text = "ARIA meter must have an accessible name";
7-
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`;
7+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
88

99
/**
1010
* Check if an element has an accessible name via aria-label, aria-labelledby, or title
@@ -43,6 +43,7 @@ export default function (element: Element): AccessibilityError[] {
4343
for (const el of elements) {
4444
if (!hasAccessibleName(el)) {
4545
errors.push({
46+
id,
4647
element: el,
4748
url,
4849
text,

src/rules/aria-progressbar-name.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { labelledByIsValid, querySelectorAll } from "../utils";
44
// Metadata
55
const id = "aria-progressbar-name";
66
const text = "ARIA progressbar must have an accessible name";
7-
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`;
7+
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`;
88

99
/**
1010
* Check if an element has an accessible name via aria-label, aria-labelledby, or title
@@ -43,6 +43,7 @@ export default function (element: Element): AccessibilityError[] {
4343
for (const el of elements) {
4444
if (!hasAccessibleName(el)) {
4545
errors.push({
46+
id,
4647
element: el,
4748
url,
4849
text,

0 commit comments

Comments
 (0)