Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIA-R65: Provide classes and number of matches in diagnostic #1164

Merged
merged 15 commits into from
Jul 8, 2022
Merged
224 changes: 0 additions & 224 deletions packages/alfa-rules/src/sia-er65/rule.ts

This file was deleted.

67 changes: 67 additions & 0 deletions packages/alfa-rules/src/sia-r65/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Diagnostic } from "@siteimprove/alfa-act";
import { Map } from "@siteimprove/alfa-map";

export type Matches = {
zsofitoth marked this conversation as resolved.
Show resolved Hide resolved
matchingTargets: number;
matchingNonTargets: number;
};

/**
* @internal
*/
export class ExtendedDiagnostic extends Diagnostic {
public static of(
message: string,
matches: Map<string, Matches> = Map.empty()
): Diagnostic {
return new ExtendedDiagnostic(message, matches);
}

private readonly _matches: Map<string, Matches>;

private constructor(message: string, matches: Map<string, Matches>) {
super(message);
this._matches = matches;
}

zsofitoth marked this conversation as resolved.
Show resolved Hide resolved
public equals(value: ExtendedDiagnostic): boolean;

public equals(value: unknown): value is this;

public equals(value: unknown): boolean {
return (
value instanceof ExtendedDiagnostic &&
value._matches.equals(this._matches)
);
}

public toJSON(): ExtendedDiagnostic.JSON {
return {
...super.toJSON(),
matches: this._matches.toJSON(),
};
}
}

/**
* @internal
*/
export namespace ExtendedDiagnostic {
export interface JSON extends Diagnostic.JSON {
matches: Map.JSON<string, Matches>;
}

export function isExtendedDiagnostic(
value: Diagnostic
): value is ExtendedDiagnostic;

export function isExtendedDiagnostic(
value: unknown
): value is ExtendedDiagnostic;

export function isExtendedDiagnostic(
value: unknown
): value is ExtendedDiagnostic {
return value instanceof ExtendedDiagnostic;
}
}
Loading