anchor-has-content
Configuration
rslint.config.ts
Rule Details
This rule enforces that anchors (<a> elements and any configured custom
anchor components) have accessible content — text or descendant elements
that screen readers can announce. An empty anchor that lacks both a title
and an aria-label is reported.
An anchor is considered to have accessible content when at least one of the following holds:
- It contains non-empty text or a non-hidden child element.
- It contains a JSX expression whose value is anything other than the bare
identifier
undefined. - It declares a
dangerouslySetInnerHTMLorchildrenprop. - It declares a
titleoraria-labelattribute.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule options
The rule accepts an options object with the following properties:
components— array of additional component names (besides the built-ina) that should be checked for accessible content.
Examples of incorrect code for this rule with { "components": ["Anchor"] }:
Examples of correct code for this rule with { "components": ["Anchor"] }: