Skip to content

Commit 78d47ef

Browse files
committed
[anchor-has-content] account for v-html and v-text on child elements
Fixes #191
1 parent c3b4150 commit 78d47ef

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/rules/__tests__/anchor-has-content.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ makeRuleTester("anchor-has-content", rule, {
1111
"<VAnchor />",
1212
"<a aria-label='This is my label' />",
1313
"<a><img alt='foo' /></a>",
14+
"<a><span v-html='msg' /></a>",
15+
"<a><span v-text='msg' /></a>",
1416
{
1517
code: "<a v-accessibleDirective='msg' />",
1618
options: [{ accessibleDirectives: ["accessibleDirective"] }]

src/utils/hasContent.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ function hasDirective(node: AST.VElement, name: string) {
1212
);
1313
}
1414

15+
function hasChildWithDirective(node: AST.VElement, name: string): boolean {
16+
return node.children.some((child) => {
17+
if (child.type !== "VElement") return false;
18+
19+
if (hasDirective(child, name)) {
20+
return true;
21+
}
22+
23+
return hasChildWithDirective(child, name)
24+
});
25+
}
26+
1527
function hasChildImageWithAlt(node: AST.VElement): boolean {
1628
return node.children.some((child) => {
1729
if (child.type === "VElement") {
@@ -46,6 +58,8 @@ function hasContent(
4658
hasAccessibleDirective(node, accessibleDirectives) ||
4759
hasDirective(node, "text") ||
4860
hasDirective(node, "html") ||
61+
hasChildWithDirective(node, "text") ||
62+
hasChildWithDirective(node, "html") ||
4963
hasChildImageWithAlt(node)
5064
);
5165
}

0 commit comments

Comments
 (0)