Skip to content
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

fixrule(img_alt_null, aria_accessiblename_exists) Update the rule mappings to be consistent with ACT rules #2108

Merged
merged 21 commits into from
Dec 11, 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
28 changes: 17 additions & 11 deletions accessibility-checker-engine/src/v4/checker/Checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,27 @@ export class Checker implements IChecker {
}
for (const rsId of rsIds) {
if (rsId in rsInfo) {
Object.keys(rsInfo[rsId]).forEach(code => {
const reCode = new RegExp(`(^|--)${reasonCode}($|--)`);
Object.keys(rsInfo[rsId]).forEach(code => {
let level = null;
const reCode = new RegExp(`(^|--)${reasonCode}($|--)`);
if (code === 'None')
level = rsInfo[rsId]["None"];
else if (reCode.test(code))
level = rsInfo[rsId][code];
if (level === eRulePolicy.VIOLATION) {
retVal = eRulePolicy.VIOLATION;
} else if (level === eRulePolicy.RECOMMENDATION && retVal === null) {
retVal = eRulePolicy.RECOMMENDATION;
} else if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
});
level = rsInfo[rsId][code];

if (level !== null) {
if (level === eRulePolicy.VIOLATION) {
retVal = eRulePolicy.VIOLATION;
} else if (level === eRulePolicy.RECOMMENDATION && retVal === null) {
retVal = eRulePolicy.RECOMMENDATION;
} else if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
}
});
if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { AriaUtil } from "../util/AriaUtil";
import { CommonUtil } from "../util/CommonUtil";
import { VisUtil } from "../util/VisUtil";
import { ARIADefinitions } from "../../v2/aria/ARIADefinitions";
import { AccNameUtil } from "../util/AccNameUtil";

export const aria_accessiblename_exists: Rule = {
Expand All @@ -26,32 +24,42 @@ export const aria_accessiblename_exists: Rule = {
"en-US": {
"pass": "aria_accessiblename_exists.html",
"fail_no_accessible_name": "aria_accessiblename_exists.html",
"fail_no_accessible_name_image": "aria_accessiblename_exists.html",
"group": "aria_accessiblename_exists.html"
}
},
messages: {
"en-US": {
"pass": "An accessible name is provided for the element",
"fail_no_accessible_name": "Element <{0}> with \"{1}\" role has no accessible name",
"fail_no_accessible_name_image": "Element <{0}> with \"{1}\" role has no accessible name",
"group": "Elements with certain roles should have accessible names"
}
},
rulesets: [{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["4.1.2"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name_image"]
}],
act: [],
act: [{"23a2a8": {"fail_no_accessible_name_image": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;

//skip the rule
if (VisUtil.isNodeHiddenFromAT(ruleContext)) return null;

let nodeName = ruleContext.nodeName.toLocaleLowerCase();
// svg element is handled in svg_graphics)labbelled rule
if (nodeName === 'svg') return;
// svg element is handled in svg_graphics_labbelled rule and image rules
if (nodeName === 'svg' || nodeName === 'img') return;

// when table element with a caption as first child
if (nodeName === 'table'
Expand All @@ -69,9 +77,11 @@ export const aria_accessiblename_exists: Rule = {
let role = AriaUtil.getResolvedRole(ruleContext);

const name_pair = AccNameUtil.computeAccessibleName(ruleContext);
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0)
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0) {
if (role === 'img' || role === 'image')
return RuleFail("fail_no_accessible_name_image", [ruleContext.nodeName.toLowerCase(), role]);
return RuleFail("fail_no_accessible_name", [ruleContext.nodeName.toLowerCase(), role]);

}
return RulePass("pass");
}
}
13 changes: 11 additions & 2 deletions accessibility-checker-engine/src/v4/rules/img_alt_null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ export const img_alt_null: Rule = {
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["1.1.1"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
}],
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_decorative"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["potential_aria_override"]
}
],
act: [{"46ca7f": {"potential_aria_override": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,7 @@
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [
{
"ruleId": "aria_accessiblename_exists",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/img[1]",
"aria": "/document[1]/img[1]"
},
"reasonId": "pass",
"message": "An accessible name is provided for the element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}

]
}
</script>
Expand Down
Loading