Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7bcf0d6

Browse files
authoredOct 21, 2021
Merge pull request #313 from vhoyer/fix-anchor-has-content-v-html
[anchor-has-content] account for v-html and v-text on child elements
2 parents c3b4150 + b25191e commit 7bcf0d6

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1010

1111
- Deprecate the accessible-emoji rule. See https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/627 for details.
1212
- Fix the `alt-text` handling of different element case names.
13+
- Fix the `anchor-has-content` handling for content directives (v-html, v-text) on child elements.
1314

1415
## [1.1.0] - 2021-10-14
1516

‎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)
Please sign in to comment.