Skip to content

Commit 4eeb950

Browse files
crisbetotjshiu
andcommitted
feat: Refine a11y scoring logic
This commit adjusts the accessibility scoring by: - Increasing the penalty coefficients for violations. - Introducing distinct penalties for repair attempts and failed repairs. - Reducing the overall score reduction percentage. These changes aim to provide a more nuanced and accurate accessibility score. Co-authored-by: Tiffany Shiu <[email protected]>
1 parent 6d479e9 commit 4eeb950

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

runner/ratings/built-in-ratings/axe-rating.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import {
88

99
// Define the scoring weights for each violation impact level as a coefficient penalty.
1010
const IMPACT_COEFFICIENTS = {
11-
critical: 0.5,
12-
serious: 0.3,
13-
moderate: 0.15,
14-
minor: 0.1,
11+
critical: 1.0,
12+
serious: 0.75,
13+
moderate: 0.5,
14+
minor: 0.25,
1515
};
1616

17+
const REPAIR_ATTEMPT_PENALTY = 0.5;
18+
const FAILED_REPAIR_PENALTY = 0.5;
19+
1720
/**
1821
* A rating that assesses the code based on Axe accessibility violations.
1922
*/
@@ -23,13 +26,11 @@ export const axeRating: PerBuildRating = {
2326
description: 'Checks for accessibility violations using the Axe-core engine.',
2427
category: RatingCategory.MEDIUM_IMPACT,
2528
id: 'axe-a11y',
26-
scoreReduction: '50%',
29+
scoreReduction: '20%',
2730
rate: ({ buildResult, axeRepairAttempts }) => {
2831
const violations = buildResult.axeViolations as Result[] | undefined;
29-
// Subtract from a starting coefficient of 1 based on the impact of each violation.
32+
// Start with a perfect score.
3033
let coefficient = 1.0;
31-
// Apply a penalty for each repair attempt.
32-
coefficient -= (axeRepairAttempts ?? 0) * 0.2;
3334
let message: string = '';
3435

3536
if (violations === undefined) {
@@ -54,8 +55,14 @@ export const axeRating: PerBuildRating = {
5455
} accessibility violations:\n\n${formattedViolations}`;
5556
}
5657

58+
// Apply penalties for repair attempts.
5759
if (axeRepairAttempts > 0) {
5860
message += `\nAxe Repair Attempts: ${axeRepairAttempts} attempt(s)`;
61+
coefficient -= axeRepairAttempts * REPAIR_ATTEMPT_PENALTY;
62+
// Apply an additional penalty if violations still exist after repairs.
63+
if (violations.length > 0) {
64+
coefficient -= FAILED_REPAIR_PENALTY;
65+
}
5966
}
6067

6168
return {

0 commit comments

Comments
 (0)