Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/rules/template-link-href-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ module.exports = {
const hasHref = node.attributes?.some((attr) => attr.name === 'href');

if (!hasHref) {
// Exception: <a> with both role and aria-disabled doesn't need href
const hasRole = node.attributes?.some((attr) => attr.name === 'role');
const hasAriaDisabled = node.attributes?.some((attr) => attr.name === 'aria-disabled');
if (hasRole && hasAriaDisabled) {
return;
}

context.report({
node,
messageId: 'missingHref',
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/template-link-href-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ ruleTester.run('template-link-href-attributes', rule, {
'<template><a href="/about">About</a></template>',
'<template><a href="https://example.com">External</a></template>',
'<template><button>Click me</button></template>',
'<template><a role="link" aria-disabled="true">valid</a></template>',
'<template><a role="button" aria-disabled="true">valid</a></template>',
'<template><a href="">Empty href</a></template>',
'<template><a href="#">Hash href</a></template>',
'<template><a href={{this.link}}>Dynamic href</a></template>',
],

invalid: [
Expand All @@ -29,5 +34,10 @@ ruleTester.run('template-link-href-attributes', rule, {
output: null,
errors: [{ messageId: 'missingHref' }],
},
{
code: '<template><a aria-disabled="true">Disabled only</a></template>',
output: null,
errors: [{ messageId: 'missingHref' }],
},
],
});
Loading