Skip to content

Commit

Permalink
Merge pull request #1232 from IBMa/refactor
Browse files Browse the repository at this point in the history
Add engine and tool support to allow rule id refactoring without updating baselines
  • Loading branch information
ErickRenteria authored Jan 26, 2023
2 parents d5b5498 + bb6e7ca commit 0a0b2b3
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 8 deletions.
7 changes: 6 additions & 1 deletion accessibility-checker-engine/README-RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ An example rule might look like:
{
id: "body_all_trigger",
context: "dom:body",
refactor: {
"OLDID_Trigger": {
"Manual_0": "manual_always"
}
},
help: {
"en-US": {
0: `body_all_trigger.html`,
"Pass_0": `body_all_trigger.html`
"manual_always": `body_all_trigger.html`
}
},
messages: {
Expand Down
6 changes: 6 additions & 0 deletions accessibility-checker-engine/src/v4/api/IRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ export type Rule = {
toolkitLevel: eToolkitLevel
}>

refactor?: {
[oldRuleId: string]: {
[oldReasonCode: string]: string
}
};

messages: {
[locale: string]: {
[reasonId: string]: string
Expand Down
9 changes: 9 additions & 0 deletions accessibility-checker/src-ts/lib/ACEngineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,13 @@ try {
}
return retVal;
}

static getRulesSync = function() {
if (!checker) return null;
let retVal = [];
for (const ruleId in checker.engine.ruleMap) {
retVal.push(checker.engine.ruleMap[ruleId]);
}
return retVal;
}
}
30 changes: 28 additions & 2 deletions accessibility-checker/src-ts/lib/ACReportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ACReporterXLSX } from "./reporters/ACReporterXLSX";
import { initializeSummary, IScanSummary } from "./reporters/ReportUtil";
import { ACReporterHTML } from "./reporters/ACReporterHTML";
import { ACReporterJSON } from "./reporters/ACReporterJSON";
import { eRuleLevel, Report } from "./api/IEngine";
import { eRuleLevel, Report, Rule } from "./api/IEngine";

export class ACReportManager {
static config: IConfigUnsupported;
Expand All @@ -21,6 +21,10 @@ export class ACReportManager {
xlsx: any
}

static refactorMap : {
[oldRuleId: string]: Rule
}

// Array that contains the list of entries that need to be compared between the actual and baseline objects only.
// Note: This is used by the cleanComplianceObjectBeforeCompare function to filter the report based on this.
static baselineIssueList = ["ruleId", "xpath"];
Expand Down Expand Up @@ -1055,8 +1059,30 @@ export class ACReportManager {
*/
static getBaseline(label) {
try {
return require(path.join(path.join(process.cwd(), ACReportManager.config.baselineFolder), label));
let retVal = require(path.join(path.join(process.cwd(), ACReportManager.config.baselineFolder), label));
if (retVal && retVal.results) {
if (!this.refactorMap) {
this.refactorMap = {}
let rules = ACEngineManager.getRulesSync();
for (const rule of rules) {
if (rule.refactor) {
for (const key in rule.refactor) {
this.refactorMap[key] = rule;
}
}
}
}
for (const result of retVal.results) {
if (result.ruleId in this.refactorMap) {
let mapping = this.refactorMap[result.ruleId].refactor[result.ruleId];
result.ruleId = this.refactorMap[result.ruleId].id;
result.reasonId = mapping[result.reasonId];
}
}
}
return retVal;
} catch (e) {
// console.error("getBaseline Error:", e);
return null;
}
};
Expand Down
6 changes: 6 additions & 0 deletions accessibility-checker/src-ts/lib/api/IEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ export type Rule = {
// See src/v2/common/Context.ts for valid contexts
context: string;

refactor?: {
[oldRuleId: string]: {
[oldReasonCode: string]: string
}
};

// Array of rules that must pass to allow this validate to run - they must have the same context property
dependencies?: string[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("Baseline testing", function () {
let result = await aChecker.getCompliance(unitTestDataFileContent, "Baseline_" + labelName);
let assertVal = aChecker.assertCompliance(result.report);
if (assertVal !== codes[unitTestFile]) {
console.log("inspect result", util.inspect(result, null, 6));
console.log("inspect result", util.inspect(result.report, null, 6));
}
expect(assertVal).to.equal(codes[unitTestFile]);
});
Expand Down
32 changes: 30 additions & 2 deletions cypress-accessibility-checker/src/lib/ACTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,40 @@ let ACTasks = module.exports = {
*/
getBaseline: function (labelStr) {
try {
return require(path.join(path.join(process.cwd(), ACTasks.Config.baselineFolder), labelStr));
let retVal = require(path.join(path.join(process.cwd(), ACTasks.Config.baselineFolder), labelStr));
if (retVal && retVal.results) {
if (!ACTasks.refactorMap) {
ACTasks.refactorMap = {}
let rules = ACTasks.getRulesSync();
for (const rule of rules) {
if (rule.refactor) {
for (const key in rule.refactor) {
ACTasks.refactorMap[key] = rule;
}
}
}
}
for (const result of retVal.results) {
if (result.ruleId in ACTasks.refactorMap) {
let mapping = ACTasks.refactorMap[result.ruleId].refactor[result.ruleId];
result.ruleId = ACTasks.refactorMap[result.ruleId].id;
result.reasonId = mapping[result.reasonId];
}
}
}
return retVal;
} catch (e) {
return null;
}
},

getRulesSync: () => {
let checker = new ACTasks.ace.Checker();
let retVal = [];
for (const ruleId in checker.engine.ruleMap) {
retVal.push(checker.engine.ruleMap[ruleId]);
}
return retVal;
},
getRulesets: () => new ACTasks.ace.Checker().rulesets,

/**
Expand Down
34 changes: 32 additions & 2 deletions karma-accessibility-checker/src/lib/ACHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ let aChecker = {
};

aChecker.getRulesets = () => new ace.Checker().rulesets;

aChecker.getRulesSync = () => {
let checker = new ace.Checker();
let retVal = [];
for (const ruleId in checker.engine.ruleMap) {
retVal.push(checker.engine.ruleMap[ruleId]);
}
return retVal;
}
/**
* This function is responsible for running the scan by calling the IBMa.validate function with the
* provided content.
Expand Down Expand Up @@ -1490,6 +1497,8 @@ let aChecker = {
return objectToClean;
};

aChecker.refactor;

/**
* This function is responsible for getting the baseline object for a label that was provided.
*
Expand All @@ -1503,7 +1512,28 @@ let aChecker = {
* @memberOf this
*/
aChecker.getBaseline = function (label) {
return window.__aChecker__ && window.__aChecker__[label];
let retVal = window.__aChecker__ && window.__aChecker__[label];
if (retVal && retVal.results) {
if (!aChecker.refactorMap) {
aChecker.refactorMap = {}
let rules = aChecker.getRulesSync();
for (const rule of rules) {
if (rule.refactor) {
for (const key in rule.refactor) {
aChecker.refactorMap[key] = rule;
}
}
}
}
for (const result of retVal.results) {
if (result.ruleId in aChecker.refactorMap) {
let mapping = aChecker.refactorMap[result.ruleId].refactor[result.ruleId];
result.ruleId = aChecker.refactorMap[result.ruleId].id;
result.reasonId = mapping[result.reasonId];
}
}
}
return retVal;
};

/**
Expand Down

0 comments on commit 0a0b2b3

Please sign in to comment.