Skip to content

Commit

Permalink
Merge pull request #1745 from IBMa/dev-1731
Browse files Browse the repository at this point in the history
fix(engine): fix mapping issue when multiple reason codes are available
  • Loading branch information
ErickRenteria authored Dec 12, 2023
2 parents b3bcc87 + c3cf94d commit 3788a6b
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions accessibility-checker-engine/src/v4/checker/Checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class Checker implements IChecker {
rulesetIds: string[] = [];
rulesetRules: { [rsId: string]: string[] } = {};
ruleLevels : { [ruleId: string]: { [rsId: string] : eRulePolicy }} = {};
ruleReasonLevels : { [ruleId: string]: { [rsId: string] : {[reasonCodes: string] : eRulePolicy }}} = {};
ruleCategory : { [ruleId: string]: { [rsId: string] : eGuidelineCategory }} = {};

public constructor() {
Expand Down Expand Up @@ -130,8 +131,12 @@ export class Checker implements IChecker {
for (const rule of cp.rules) {
if (rule.enabled !== false) {
ruleIds.push(rule.id);
this.ruleLevels[rule.id] = this.ruleLevels[rule.id] || {};
this.ruleLevels[rule.id][guideline.id] = rule.level;
//this.ruleLevels[rule.id] = this.ruleLevels[rule.id] || {};
//this.ruleLevels[rule.id][guideline.id] = rule.level;
this.ruleReasonLevels[rule.id] = this.ruleReasonLevels[rule.id] || {};
this.ruleReasonLevels[rule.id][guideline.id] = this.ruleReasonLevels[rule.id][guideline.id] || {};
const code = rule.reasonCodes ? rule.reasonCodes.join('--') : "None";
this.ruleReasonLevels[rule.id][guideline.id][code] = rule.level;
this.ruleCategory[rule.id] = this.ruleCategory[rule.id] || {};
this.ruleCategory[rule.id][guideline.id] = guideline.category;
}
Expand Down Expand Up @@ -243,10 +248,8 @@ export class Checker implements IChecker {
ruleIds = ruleIds.concat(this.rulesetRules[rsId]);
}
}
}

}
this.engine.enableRules(ruleIds);

// Add the report levels
let myThis = this;
return this.engine.run(node)
Expand All @@ -262,7 +265,9 @@ export class Checker implements IChecker {
report.nls[result.ruleId][result.reasonId] = checkNls[result.ruleId][result.reasonId];
}
}
result.value[0] = myThis.getLevel(guidelineIds as string[], result.ruleId);
//result.value[0] = myThis.getLevel(guidelineIds as string[], result.ruleId);
let code = result.reasonId? result.reasonId as string : "None";
result.value[0] = myThis.getReasonLevel(guidelineIds as string[], result.ruleId, code);
result.category = myThis.getCategory(guidelineIds as string[], result.ruleId);
delete result.path.css;
}
Expand Down Expand Up @@ -296,6 +301,40 @@ export class Checker implements IChecker {
return retVal;
}

private getReasonLevel(rsIds: string[], ruleId: string, reasonCode?: string) : eRulePolicy {
if (!rsIds) return eRulePolicy.INFORMATION;
let rsInfo = this.ruleReasonLevels[ruleId];
let retVal = null;
if (rsIds) {
if (!(ruleId in this.ruleReasonLevels)) {
throw new Error("Rule triggered for which we have no rule level information "+ruleId);
}
for (const rsId of rsIds) {
if (rsId in rsInfo) {
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;
}
});
}
}
}
if (retVal === null) {
throw new Error("Rule triggered for which we have no rule level information: "+ruleId);
}
return retVal;
}

private getCategory(rsIds: string[], ruleId?: string) : eGuidelineCategory {
let rsInfo = this.ruleCategory[ruleId];
let retVal = "";
Expand Down

0 comments on commit 3788a6b

Please sign in to comment.