Skip to content

Commit

Permalink
feat: added message logs from axe-core violation (#676)
Browse files Browse the repository at this point in the history
* feat: added message logs from axe-core violation

* feat: improved formatSpacing
  • Loading branch information
jaig-0911 authored May 7, 2024
1 parent 03c66b2 commit 51eb9c7
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 109 deletions.
9 changes: 9 additions & 0 deletions packages/format/src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NodeResult, Result } from 'axe-core';
import { priorities, wcagLevels, WcagMetadata } from '@sa11y/preset-rules';

const defaultImpact = 'minor'; // if impact is undefined
const formatSpacing = '\t'.repeat(12);
// Helper object to sort violations by impact order
const impactOrder = {
critical: 1,
Expand Down Expand Up @@ -83,6 +84,10 @@ export class A11yResult {
public readonly wcag: string;
public readonly summary: string;
public readonly key: string; // Represent a key with uniquely identifiable info
public readonly ancestry: string;
public readonly any: string;
public readonly all: string;
public readonly none: string;
private readonly wcagData: WcagMetadata; // Used to sort results

constructor(violation: Result, node: NodeResult) {
Expand All @@ -97,6 +102,10 @@ export class A11yResult {
/* istanbul ignore next */
this.summary = node.failureSummary || '';
this.key = `${this.id}--${this.selectors}`;
this.ancestry = (node.ancestry?.flat(Infinity) ?? []).join('\n');
this.any = node.any?.map((item) => `${formatSpacing}${item.message}`).join('\n');
this.all = node.all?.map((item) => `${formatSpacing}${item.message}`).join('\n');
this.none = node.none?.map((item) => `${formatSpacing}${item.message}`).join('\n');
}

/**
Expand Down
Loading

0 comments on commit 51eb9c7

Please sign in to comment.