Rule class

Base class for rules.

options property

Syntax

readonly options: OptionsType

Object with all the options passed from the configuration. Options are accessed using this.options.

When using TypeScript, pass the datatype as the second template argument when extending Rule. The default is void (i.e. no options).

on() method

Listen for events. See the events guide for a full list of available events and data.

If filter is passed, the callback is only called if the filter function evaluates to true.

Syntax

on<K extends keyof ListenEventMap>(event: K, callback: (event: ListenEventMap[K]) => void): () => void;
on<K extends keyof ListenEventMap>(event: K, filter: (event: ListenEventMap[K]) => boolean, callback: (event: ListenEventMap[K]) => void): () => void;

Return value

A function to unregister the event listener.

Parameters

report() method

Report a new error.

Syntax

report(error: ErrorDescriptor<ContextType>): void;

Return value

No return value.

Parameters

getMetaFor() method

Syntax

getMetaFor(tagName: string): MetaElement | null

Return value

Metadata for the tag, or null if neither tag-specific nor global metadata exists.

Parameters

getTagsWithProperty() method

Syntax

getTagsWithProperty(propName: MetaLookupableProperty): string[]

Return value

Names of all tags with the given property enabled.

Parameters

getTagsDerivedFrom() method

Syntax

getTagsDerivedFrom(tagName: string): string[]

Return value

Names of tags matching tagName or inheriting from it.

Parameters

getAriaVersion() method

Syntax

getAriaVersion();

Return value

The configured ARIA specification version: "1.2", "1.3", or "latest". Returns "1.2" by default and preserves "latest" when configured rather than resolving it to a numbered version.

isValidAriaRole() method

Syntax

isValidAriaRole(role: string): role is AriaRole;

Return value

Returns true if the role is defined in the configured ARIA specification version. When true, the argument is narrowed to AriaRole.

Parameters

getAriaRoleData() method

Syntax

getAriaRoleData(role: AriaRole): NormalizedRole;
getAriaRoleData(role: string): NormalizedRole | null;

Return value

Metadata for the role, or null if the role is not defined in the configured version.

Parameters

getAriaRoles() method

Syntax

getAriaRoles([filter]);

Return value

A generator yielding metadata for each defined role in the configured ARIA specification version, including abstract roles. When a filter is provided, only matching roles are yielded.

Parameters

Examples

for (const role of this.getAriaRoles()) {
  console.log(role.role, role.category);
}