Skip to content

Commit b691ce6

Browse files
Merge pull request #2494 from johanrd/fix/2395
Post-merge review of #2395 (`template-link-href-attributes`)
2 parents ebf2a2a + 66570cc commit b691ce6

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/rules/template-link-href-attributes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ module.exports = {
2727
const hasHref = node.attributes?.some((attr) => attr.name === 'href');
2828

2929
if (!hasHref) {
30+
// Exception: <a> with both role and aria-disabled doesn't need href
31+
const hasRole = node.attributes?.some((attr) => attr.name === 'role');
32+
const hasAriaDisabled = node.attributes?.some((attr) => attr.name === 'aria-disabled');
33+
if (hasRole && hasAriaDisabled) {
34+
return;
35+
}
36+
3037
context.report({
3138
node,
3239
messageId: 'missingHref',

tests/lib/rules/template-link-href-attributes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ ruleTester.run('template-link-href-attributes', rule, {
1111
'<template><a href="/about">About</a></template>',
1212
'<template><a href="https://example.com">External</a></template>',
1313
'<template><button>Click me</button></template>',
14+
'<template><a role="link" aria-disabled="true">valid</a></template>',
15+
'<template><a role="button" aria-disabled="true">valid</a></template>',
16+
'<template><a href="">Empty href</a></template>',
17+
'<template><a href="#">Hash href</a></template>',
18+
'<template><a href={{this.link}}>Dynamic href</a></template>',
1419
],
1520

1621
invalid: [
@@ -29,5 +34,10 @@ ruleTester.run('template-link-href-attributes', rule, {
2934
output: null,
3035
errors: [{ messageId: 'missingHref' }],
3136
},
37+
{
38+
code: '<template><a aria-disabled="true">Disabled only</a></template>',
39+
output: null,
40+
errors: [{ messageId: 'missingHref' }],
41+
},
3242
],
3343
});

0 commit comments

Comments
 (0)