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
4 changes: 4 additions & 0 deletions docs/review/api/alfa-rules.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ export namespace Diagnostic {
//
// (undocumented)
isDistinguishingStylesExperimental: typeof DistinguishingStyles_2.isDistinguishingStyles;
const // Warning: (ae-forgotten-export) The symbol "MatchingClasses" needs to be exported by the entry point index.d.ts
//
// (undocumented)
isMatchingClasses: typeof MatchingClasses.isMatchingClasses;
const // Warning: (ae-forgotten-export) The symbol "LabelAndName" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down
3 changes: 3 additions & 0 deletions packages/alfa-rules/src/common/act/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LabelAndName } from "../../sia-r14/rule";
import { RoleAndRequiredAttributes } from "../../sia-r16/rule";
import { SameNames } from "../../sia-r56/rule";
import { DistinguishingStyles } from "../../sia-r62/rule";
import { MatchingClasses } from "../../sia-r65/diagnostics";
import { DeprecatedElements } from "../../sia-r70/rule";
import { WithDeclaration } from "../../sia-r75/rule";
import { ClippingAncestors } from "../../sia-r83/rule";
Expand Down Expand Up @@ -37,6 +38,8 @@ export namespace Diagnostic {
export const { isDistinguishingStyles: isDistinguishingStylesExperimental } =
DistinguishingStylesExperimental;

export const { isMatchingClasses } = MatchingClasses;

export const { isLabelAndName } = LabelAndName;

export const { isLanguages } = Languages;
Expand Down
224 changes: 0 additions & 224 deletions packages/alfa-rules/src/sia-er65/rule.ts

This file was deleted.

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

export class MatchingClasses extends Diagnostic {
public static of(
message: string,
matchingTargets: Map<string, number> = Map.empty(),
matchingNonTargets: Map<string, number> = Map.empty()
): Diagnostic {
return new MatchingClasses(message, matchingTargets, matchingNonTargets);
}

private readonly _matchingTargets: Map<string, number>;
private readonly _matchingNonTargets: Map<string, number>;

private constructor(
message: string,
matchingTargets: Map<string, number>,
matchingNonTargets: Map<string, number>
) {
super(message);
this._matchingTargets = matchingTargets;
this._matchingNonTargets = matchingNonTargets;
}

zsofitoth marked this conversation as resolved.
Show resolved Hide resolved
public get matchingTargets(): Map<string, number> {
return this._matchingTargets;
}

public get matchingNonTargets(): Map<string, number> {
return this._matchingNonTargets;
}

public equals(value: MatchingClasses): boolean;

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

public equals(value: unknown): boolean {
return (
value instanceof MatchingClasses &&
value._matchingTargets.equals(this._matchingTargets) &&
value._matchingNonTargets.equals(this._matchingNonTargets)
);
}

public toJSON(): MatchingClasses.JSON {
return {
...super.toJSON(),
matchingTargets: this._matchingTargets.toJSON(),
zsofitoth marked this conversation as resolved.
Show resolved Hide resolved
matchingNonTargets: this._matchingNonTargets.toJSON(),
};
}
}

/**
* @internal
*/
export namespace MatchingClasses {
export interface JSON extends Diagnostic.JSON {
matchingTargets: Map.JSON<string, number>;
matchingNonTargets: Map.JSON<string, number>;
}

export function isMatchingClasses(
value: Diagnostic
): value is MatchingClasses;

export function isMatchingClasses(value: unknown): value is MatchingClasses;

export function isMatchingClasses(value: unknown): value is MatchingClasses {
return value instanceof MatchingClasses;
}
}
Loading