From 87a55c8d79891baa078e48694f7ea56a6806f236 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Mon, 13 Nov 2023 16:06:59 -0600 Subject: [PATCH 1/4] Update Checker.ts --- .../src/v4/checker/Checker.ts | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/accessibility-checker-engine/src/v4/checker/Checker.ts b/accessibility-checker-engine/src/v4/checker/Checker.ts index 1604c24f6..e185f6288 100644 --- a/accessibility-checker-engine/src/v4/checker/Checker.ts +++ b/accessibility-checker-engine/src/v4/checker/Checker.ts @@ -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() { @@ -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; } @@ -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) @@ -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; } @@ -296,6 +301,39 @@ 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; + if (code === 'None') + level = rsInfo[rsId]["None"]; + else if (code.includes(reasonCode)) + 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 = ""; From dfaabe4b992c38cca8ab34bc2248844ef3fb98c3 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 14 Nov 2023 16:21:58 -0600 Subject: [PATCH 2/4] Update Checker.ts --- accessibility-checker-engine/src/v4/checker/Checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accessibility-checker-engine/src/v4/checker/Checker.ts b/accessibility-checker-engine/src/v4/checker/Checker.ts index e185f6288..27215658b 100644 --- a/accessibility-checker-engine/src/v4/checker/Checker.ts +++ b/accessibility-checker-engine/src/v4/checker/Checker.ts @@ -135,7 +135,7 @@ export class Checker implements IChecker { //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"; + 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; @@ -315,7 +315,7 @@ export class Checker implements IChecker { let level = null; if (code === 'None') level = rsInfo[rsId]["None"]; - else if (code.includes(reasonCode)) + else if ((code.includes("--") && code.includes(reasonCode+"--")) || code.includes(reasonCode)) level = rsInfo[rsId][code]; if (level === eRulePolicy.VIOLATION) { retVal = eRulePolicy.VIOLATION; From 45cdc8ce3a8fea180789229185efb45f194292fe Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 14 Nov 2023 17:29:06 -0600 Subject: [PATCH 3/4] Update Checker.ts --- accessibility-checker-engine/src/v4/checker/Checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accessibility-checker-engine/src/v4/checker/Checker.ts b/accessibility-checker-engine/src/v4/checker/Checker.ts index 27215658b..74b94c216 100644 --- a/accessibility-checker-engine/src/v4/checker/Checker.ts +++ b/accessibility-checker-engine/src/v4/checker/Checker.ts @@ -315,7 +315,7 @@ export class Checker implements IChecker { let level = null; if (code === 'None') level = rsInfo[rsId]["None"]; - else if ((code.includes("--") && code.includes(reasonCode+"--")) || code.includes(reasonCode)) + else if ((code.includes("--") && (code.includes(reasonCode+"--") || code.includes("--"+reasonCode))) || (!code.includes("--") && code.includes(reasonCode))) level = rsInfo[rsId][code]; if (level === eRulePolicy.VIOLATION) { retVal = eRulePolicy.VIOLATION; From 26a43c2f0182e0a1caa5b3b790e74a7e8c6bea0d Mon Sep 17 00:00:00 2001 From: Shunguo Date: Thu, 16 Nov 2023 09:41:28 -0600 Subject: [PATCH 4/4] Update Checker.ts --- accessibility-checker-engine/src/v4/checker/Checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accessibility-checker-engine/src/v4/checker/Checker.ts b/accessibility-checker-engine/src/v4/checker/Checker.ts index 74b94c216..aaab4076e 100644 --- a/accessibility-checker-engine/src/v4/checker/Checker.ts +++ b/accessibility-checker-engine/src/v4/checker/Checker.ts @@ -313,9 +313,10 @@ export class Checker implements IChecker { 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 ((code.includes("--") && (code.includes(reasonCode+"--") || code.includes("--"+reasonCode))) || (!code.includes("--") && code.includes(reasonCode))) + else if (reCode.test(code)) level = rsInfo[rsId][code]; if (level === eRulePolicy.VIOLATION) { retVal = eRulePolicy.VIOLATION;