Skip to content

anchorValidity

Reports invalid usage of anchor elements.

✅ This rule is included in the jsx logical and logicalStrict presets.

The HTML <a> (“anchor”) element represents a link to some place on the current page or another page. If an <a> does not have a valid href attribute than it is not a valid anchor.

Invalid anchors are most commonly seen when developers use an <a> with an onClick, rather than the more semantic <button>. Anchor elements should only be used for navigation, not triggering modifications to the current page.

<
any
a
/>
<
any
a
href: string
href
="#" />
<
any
a
href: string
href
="javascript:void(0)" />
<
any
a
onClick: () => void
onClick
={() => {}} />
<
any
a
href: string
href
="#"
onClick: () => void
onClick
={() => {}} />

If you use a framework that automatically populates anchors with proper href attributes, then you can disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.