From a6024eb0419964d7e391bf29e283192dd5e50c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Christian=20J=C3=B8rgensen?= <114920418+rcj-siteimprove@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:24:52 +0100 Subject: [PATCH] Rename diagnostic `WithAccessibleName` to `WithName` and property `accessibleName` to `name` (#1537) * Rename `accessibleName` to `name` * Extract API * Add changeset --- .changeset/few-ravens-shave.md | 7 ++ docs/review/api/alfa-rules.api.md | 2 +- .../alfa-rules/src/common/act/diagnostic.ts | 2 +- packages/alfa-rules/src/common/diagnostic.ts | 2 +- .../common/diagnostic/with-accessible-name.ts | 71 -------------- .../src/common/diagnostic/with-name.ts | 62 +++++++++++++ packages/alfa-rules/src/sia-r15/rule.ts | 26 ++---- packages/alfa-rules/src/sia-r39/rule.ts | 21 ++--- packages/alfa-rules/src/sia-r41/rule.ts | 30 ++---- packages/alfa-rules/src/sia-r81/rule.ts | 30 ++---- .../alfa-rules/test/sia-r15/rule.spec.tsx | 92 ++++++++----------- .../alfa-rules/test/sia-r39/rule.spec.tsx | 4 +- .../alfa-rules/test/sia-r41/rule.spec.tsx | 4 +- .../alfa-rules/test/sia-r81/rule.spec.tsx | 4 +- packages/alfa-rules/tsconfig.json | 2 +- 15 files changed, 158 insertions(+), 201 deletions(-) create mode 100644 .changeset/few-ravens-shave.md delete mode 100644 packages/alfa-rules/src/common/diagnostic/with-accessible-name.ts create mode 100644 packages/alfa-rules/src/common/diagnostic/with-name.ts diff --git a/.changeset/few-ravens-shave.md b/.changeset/few-ravens-shave.md new file mode 100644 index 0000000000..38df0d3cff --- /dev/null +++ b/.changeset/few-ravens-shave.md @@ -0,0 +1,7 @@ +--- +"@siteimprove/alfa-rules": minor +--- + +**Breaking:** Diagnostic `WithAccessibleName` has been renamed to `WithName` and the property `accessibleName` to `name`. + +This is to conform to existing diagnostics that refer to accessible name as name and clients that are expecting this convention. diff --git a/docs/review/api/alfa-rules.api.md b/docs/review/api/alfa-rules.api.md index 1baff7a595..f90e5741c7 100644 --- a/docs/review/api/alfa-rules.api.md +++ b/docs/review/api/alfa-rules.api.md @@ -83,7 +83,7 @@ export namespace Diagnostic { import TextSpacing = diagnostic.TextSpacing; import WithBadElements = diagnostic.WithBadElements; import WithRole = diagnostic.WithRole; - import WithAccessibleName = diagnostic.WithAccessibleName; + import WithName = diagnostic.WithName; import WithOtherHeading = diagnostic.WithOtherHeading; } diff --git a/packages/alfa-rules/src/common/act/diagnostic.ts b/packages/alfa-rules/src/common/act/diagnostic.ts index 73efc55a2e..a04338cabd 100755 --- a/packages/alfa-rules/src/common/act/diagnostic.ts +++ b/packages/alfa-rules/src/common/act/diagnostic.ts @@ -36,6 +36,6 @@ export namespace Diagnostic { export import TextSpacing = diagnostic.TextSpacing; export import WithBadElements = diagnostic.WithBadElements; export import WithRole = diagnostic.WithRole; - export import WithAccessibleName = diagnostic.WithAccessibleName; + export import WithName = diagnostic.WithName; export import WithOtherHeading = diagnostic.WithOtherHeading; } diff --git a/packages/alfa-rules/src/common/diagnostic.ts b/packages/alfa-rules/src/common/diagnostic.ts index 731a8d70f5..8f989d49b3 100644 --- a/packages/alfa-rules/src/common/diagnostic.ts +++ b/packages/alfa-rules/src/common/diagnostic.ts @@ -5,5 +5,5 @@ export * from "./diagnostic/contrast"; export * from "./diagnostic/text-spacing"; export * from "./diagnostic/with-bad-elements"; export * from "./diagnostic/with-role"; -export * from "./diagnostic/with-accessible-name"; +export * from "./diagnostic/with-name"; export * from "./diagnostic/with-other-heading"; diff --git a/packages/alfa-rules/src/common/diagnostic/with-accessible-name.ts b/packages/alfa-rules/src/common/diagnostic/with-accessible-name.ts deleted file mode 100644 index c9575da7d3..0000000000 --- a/packages/alfa-rules/src/common/diagnostic/with-accessible-name.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Diagnostic } from "@siteimprove/alfa-act"; -import { Device } from "@siteimprove/alfa-device"; -import { Node } from "@siteimprove/alfa-aria"; -import { Element } from "@siteimprove/alfa-dom"; -import { Option } from "@siteimprove/alfa-option"; - -/** - * @public - */ -export class WithAccessibleName extends Diagnostic { - public static of(message: string): Diagnostic; - - public static of(message: string, accessibleName: string): Diagnostic; - - public static of(message: string, accessibleName?: string): Diagnostic { - return accessibleName === undefined - ? new Diagnostic(message) - : new WithAccessibleName(message, accessibleName); - } - - private readonly _accessibleName: string; - - protected constructor(message: string, accessibleName: string) { - super(message); - this._accessibleName = accessibleName; - } - - public get accessibleName(): string { - return this._accessibleName; - } - - public toJSON(): WithAccessibleName.JSON { - return { - ...super.toJSON(), - accessibleName: this._accessibleName, - }; - } -} - -/** - * @public - */ -export namespace WithAccessibleName { - export interface JSON extends Diagnostic.JSON { - accessibleName: string; - } - - export function isWithAccessibleName( - value: Diagnostic, - ): value is WithAccessibleName; - - export function isWithAccessibleName( - value: unknown, - ): value is WithAccessibleName; - - /** - * @public - */ - export function isWithAccessibleName( - value: unknown, - ): value is WithAccessibleName { - return value instanceof WithAccessibleName; - } - - export function getAccessibleName( - element: Element, - device: Device, - ): Option { - return Node.from(element, device).name.map((x) => x.value); - } -} diff --git a/packages/alfa-rules/src/common/diagnostic/with-name.ts b/packages/alfa-rules/src/common/diagnostic/with-name.ts new file mode 100644 index 0000000000..d2179335b7 --- /dev/null +++ b/packages/alfa-rules/src/common/diagnostic/with-name.ts @@ -0,0 +1,62 @@ +import { Diagnostic } from "@siteimprove/alfa-act"; +import { Device } from "@siteimprove/alfa-device"; +import { Node } from "@siteimprove/alfa-aria"; +import { Element } from "@siteimprove/alfa-dom"; +import { Option } from "@siteimprove/alfa-option"; + +/** + * @public + */ +export class WithName extends Diagnostic { + public static of(message: string): Diagnostic; + + public static of(message: string, name: string): Diagnostic; + + public static of(message: string, name?: string): Diagnostic { + return name === undefined + ? new Diagnostic(message) + : new WithName(message, name); + } + + private readonly _name: string; + + protected constructor(message: string, name: string) { + super(message); + this._name = name; + } + + public get name(): string { + return this._name; + } + + public toJSON(): WithName.JSON { + return { + ...super.toJSON(), + name: this._name, + }; + } +} + +/** + * @public + */ +export namespace WithName { + export interface JSON extends Diagnostic.JSON { + name: string; + } + + export function isWithName(value: Diagnostic): value is WithName; + + export function isWithName(value: unknown): value is WithName; + + /** + * @public + */ + export function isWithName(value: unknown): value is WithName { + return value instanceof WithName; + } + + export function getName(element: Element, device: Device): Option { + return Node.from(element, device).name.map((x) => x.value); + } +} diff --git a/packages/alfa-rules/src/sia-r15/rule.ts b/packages/alfa-rules/src/sia-r15/rule.ts index 9195db3ca0..4be3ff76ca 100644 --- a/packages/alfa-rules/src/sia-r15/rule.ts +++ b/packages/alfa-rules/src/sia-r15/rule.ts @@ -16,7 +16,7 @@ import { Question } from "../common/act/question"; import { referenceSameResource } from "../common/predicate"; import { Scope, Stability } from "../tags"; -import { WithAccessibleName } from "../common/diagnostic"; +import { WithName } from "../common/diagnostic"; import { normalize } from "../common/normalize"; const { hasNonEmptyAccessibleName, isIncludedInTheAccessibilityTree } = DOM; @@ -58,7 +58,7 @@ export default Rule.Atomic.of, Question.Metadata>({ referenceSameResource(response.url)(element, elements[i - 1]), ); - const name = WithAccessibleName.getAccessibleName( + const name = WithName.getName( Iterable.first(target).getUnsafe(), // Existence of first element is guaranteed by applicability device, ).getUnsafe(); // Existence of accessible name is guaranteed by applicability @@ -73,7 +73,7 @@ export default Rule.Atomic.of, Question.Metadata>({ target, "Do the