Skip to content

Commit

Permalink
SIA-R65: Provide classes and number of matches in diagnostic (#1164)
Browse files Browse the repository at this point in the history
* SIA-ER65: Split result to show why we pass

* Simplify reason

* Updated PR according to review comments

* Removed ER65, moved extended diagnostics to R65 and introduced number of matches

* Updated nonTargets to exclude targets

* Seperated matchingTargets and matchingNonTargets

* Ran yarn document

* Polish code

* Cleanup

* Fix up test
  • Loading branch information
Zsófia Tóth authored Jul 8, 2022
1 parent 5c6fa6c commit 377153e
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 792 deletions.
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 @@ -368,6 +368,10 @@ export namespace Diagnostic {
//
// (undocumented)
isDistinguishingStylesDeprecated: 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 @@ -3,6 +3,7 @@ import { Languages } from "../../sia-r109/rule";
import { LabelAndName } from "../../sia-r14/rule";
import { RoleAndRequiredAttributes } from "../../sia-r16/rule";
import { SameNames } from "../../sia-r56/rule";
import { MatchingClasses } from "../../sia-r65/diagnostics";
import { DistinguishingStyles as DeprecatedDistinguishingStyles } from "../../sia-dr62/rule";
import { DeprecatedElements } from "../../sia-r70/rule";
import { WithDeclaration } from "../../sia-r75/rule";
Expand Down Expand Up @@ -37,6 +38,8 @@ export namespace Diagnostic {
export const { isDistinguishingStyles: isDistinguishingStylesDeprecated } =
DeprecatedDistinguishingStyles;

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;
}

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(),
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

0 comments on commit 377153e

Please sign in to comment.