Why this matters
Anchor tags (<a>) are intended for navigation, not actions. Using them as buttons can cause accessibility issues and unexpected behavior. Use <button> for actions to ensure proper functionality and accessibility.
Detect cases where <a> elements are used as buttons. Anchor tags should be used for navigation, while actions should be assigned to <button> elements to maintain accessibility and expected behavior.
Anchor tags (<a>) are intended for navigation, not actions. Using them as buttons can cause accessibility issues and unexpected behavior. Use <button> for actions to ensure proper functionality and accessibility.
Side-by-side examples engineers can pattern-match during review.
const MyComponent = () => {
return <>
<a href="javascript:void(0)" onClick={foo}>Perform action</a>
<a href="#" onClick={foo}>Perform action</a>
<a onClick={foo}>Perform action</a>
</>;
};const MyComponent = () => {
return <>
<button onClick={foo}>Perform action</button>
<a href="#section" onClick={foo}>Perform action</a>
</>;
};const MyComponent = () => {
return <>
<a href="javascript:void(0)" onClick={foo}>Perform action</a>
<a href="#" onClick={foo}>Perform action</a>
<a onClick={foo}>Perform action</a>
</>;
};const MyComponent = () => {
return <>
<button onClick={foo}>Perform action</button>
<a href="#section" onClick={foo}>Perform action</a>
</>;
};From the same buckets as this rule.