Skip to content

Commit

Permalink
Merge pull request #1692 from IBMa/issue-1663
Browse files Browse the repository at this point in the history
feature(engine): Add support to engine for splitting success criteria based on reason code
  • Loading branch information
ErickRenteria authored Sep 27, 2023
2 parents 581881c + 881b4b3 commit 41527d7
Show file tree
Hide file tree
Showing 41 changed files with 973 additions and 713 deletions.
25 changes: 16 additions & 9 deletions accessibility-checker-engine/src/genHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import { exec } from "child_process";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { Rule as RuleV4 } from "./v4/api/IRule";
import { Guideline } from "./v4/api/IGuideline";

//requiring path and fs modules
const path = require('path');
const rulesV4 = require("./v4/rules");
const rulesets = require("./v4/rulesets");
const { a11yRulesets } = require("./v4/rulesets");

function myExec(cmd: string) : Promise<string> {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -136,7 +137,7 @@ width="16px" height="16px" viewBox="0 0 16 16" style="enable-background:new 0 0

function processRules() {
let retVal = [];
for (const ruleset of rulesets.a11yRulesets) {
for (const ruleset of a11yRulesets as Guideline[]) {
if (ruleset.type === "extension") continue;
let rsInfo = {
id: ruleset.id,
Expand All @@ -153,27 +154,33 @@ function processRules() {
rules: []
}
for (const ruleId in rulesV4) {
let includeRule = false;
let rule = rulesV4[ruleId];
let includeRuleCodes = new Set<string>();
let rule: RuleV4 = rulesV4[ruleId];
let rsLevel = "";
let toolkitLevel;
for (const rsInfo of rule.rulesets) {
if ((rsInfo.id === ruleset.id || rsInfo.id.includes(ruleset.id)) && (rsInfo.num === cp.num || rsInfo.num.includes(cp.num))) {
includeRule = true;
if (rsInfo.reasonCodes) {
rsInfo.reasonCodes.forEach(code => includeRuleCodes.add(code));
} else {
for (const code in rule.messages["en-US"]) {
includeRuleCodes.add(code);
}
}
rsLevel = rsInfo.level;
toolkitLevel = rsInfo.toolkitLevel;
break;
}
}
if (includeRule) {
if (includeRuleCodes.size > 0) {
let ruleInfo = {
level: rsLevel,
toolkitLevel: toolkitLevel,
rule: rule,
reasons: []
}
for (const msgCode in rule.messages["en-US"]) {
if (msgCode === "group") continue;
includeRuleCodes.forEach((msgCode) => {
if (msgCode === "group") return;
let re = new RegExp(`\\.Rule([^()) ]+)[ ()]+["']${msgCode}["']`);
let reMatch = re.exec(rule.run.toString());
if (reMatch && reMatch[1] !== "Pass") {
Expand All @@ -184,7 +191,7 @@ function processRules() {
type: reMatch[1]
})
}
}
})
ruleInfo.reasons.sort((a,b) => {
if (a.type === b.type) return 0;
if (a.level === "Fail") return -1;
Expand Down
30 changes: 7 additions & 23 deletions accessibility-checker-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
limitations under the License.
*****************************************************************************/

import { Context } from "./v2/common/Context"
export { Context } from "./v2/common/Context"
// import { Simulator } from "./v2/simulator"
import { Checker } from "./v4/checker/Checker"
import { ARIAMapper } from "./v2/aria/ARIAMapper";
import { Config } from "./v2/config/Config";
import { DOMWalker } from "./v2/dom/DOMWalker";
export { Checker }
export { ARIAMapper } from "./v2/aria/ARIAMapper";
export { Config } from "./v2/config/Config";
export { DOMWalker } from "./v2/dom/DOMWalker";

String.prototype.startsWith = String.prototype.startsWith || function (str) {
return this.indexOf(str) === 0;
Expand All @@ -30,23 +31,8 @@ String.prototype.includes = String.prototype.includes || function (str) {
Array.prototype.includes = Array.prototype.includes || function (str) {
return this.indexOf(str) !== -1;
}
/*
function simDemo(timeout?: number) {
if (!timeout) timeout = 0;
setTimeout(function() {
let sim = new Simulator();
let s = sim.renderItem(document.documentElement);
console.group("--- Item View ---");
console.log(s);
console.groupEnd();
console.group("--- Link View ---");
s = sim.renderLink(document.documentElement);
console.log(s);
console.groupEnd();
}, timeout);
}
*/
function checkDemo(timeout?: number) {

export function checkDemo(timeout?: number) {
if (!timeout) timeout = 0;
let checker = new Checker();
setTimeout(function() {
Expand Down Expand Up @@ -103,5 +89,3 @@ function checkDemo(timeout?: number) {
});
}, timeout);
}

export { Checker, Context, ARIAMapper, checkDemo, Config/*, simDemo*/, DOMWalker };
Loading

0 comments on commit 41527d7

Please sign in to comment.