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
event: Event name.callback: Function called when the event is delivered.filter: Optional function; the callback is only called when the filter returnstrue.
report() method
Report a new error.
Syntax
report(error: ErrorDescriptor<ContextType>): void;
Return value
No return value.
Parameters
error.node: DOMNode | null: The node the error belongs to.error.message: string: Error message.error.location?: Location | null: Optional precise location of the error (defaults to the node location).error.context?: ContextType: Optional data passed todocumentation()to provide contextual documentation.error.related?: Optional list of related elements, each withkind: "element"and aDOMNode | nullnode; may benull.error.fix?: Optional callback receiving anErrorFixerto automatically fix the error; may benull.error.suggestions?: Optional list of suggested fixes, each with a message and anErrorFixercallback; may benull.
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
tagName: Tag name to look up.
getTagsWithProperty() method
Syntax
getTagsWithProperty(propName: MetaLookupableProperty): string[]
Return value
Names of all tags with the given property enabled.
Parameters
propName: Metadata property to look up.
getTagsDerivedFrom() method
Syntax
getTagsDerivedFrom(tagName: string): string[]
Return value
Names of tags matching tagName or inheriting from it.
Parameters
tagName: Tag name to match or inherit from.
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
role: Role name to check.
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
role: Role name to look up; validate a string withisValidAriaRole()first to narrow it toAriaRolefor the non-null overload.
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
filter: Optional callback returningtrueto include the role metadata it receives orfalseto exclude it; if omitted, all defined roles are included.
Examples
for (const role of this.getAriaRoles()) {
console.log(role.role, role.category);
}