Skip to content

Commit 0658e29

Browse files
committed
fix+docs+test: trim whitespace, tighten JSDoc, add whitespace-only coverage (Copilot review)
- JSDoc for hasNonEmptyTextAttr() rewritten: no longer overstates the guarantee for dynamic values, and notes that aria-labelledby IDREFs are not validated. - Added invalid-case coverage for whitespace-only aria-label / aria-labelledby / title — ACCNAME 1.2 §4.3.2 step 2D. - hasNonEmptyTextAttr() already trims static values, so the new whitespace-only cases flag without further rule changes.
1 parent cb08476 commit 0658e29

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

lib/rules/template-require-valid-alt-text.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ function hasAnyAttr(node, names) {
1212
return names.some((name) => hasAttr(node, name));
1313
}
1414

15-
// For accessible-name fallback attributes (aria-label, aria-labelledby, title),
16-
// an empty string provides no accessible name — it must be checked as "any truthy
17-
// static value" or "any dynamic value". Returns true iff the attribute is
18-
// present AND will meaningfully contribute an accessible name.
15+
/**
16+
* Returns true if the named attribute is present with a non-empty, non-whitespace
17+
* static value, OR present with a dynamic (mustache/concat) value. Dynamic values
18+
* are assumed to resolve to a meaningful name at runtime (we can't verify at lint
19+
* time). Static empty-string / whitespace-only values return false — per ACCNAME 1.2
20+
* §4.3.2 step 2D.
21+
*
22+
* NOTE: This does not validate that aria-labelledby IDREFs reference existing IDs.
23+
* Rule consumers should layer that check separately if needed.
24+
*/
1925
function hasNonEmptyTextAttr(node, name) {
2026
const attr = findAttr(node, name);
2127
if (!attr?.value) {

tests/lib/rules/template-require-valid-alt-text.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ ruleTester.run('template-require-valid-alt-text', rule, {
106106
output: null,
107107
errors: [{ messageId: 'areaMissing' }],
108108
},
109+
// Whitespace-only values are not valid accessible names per ACCNAME 1.2 §4.3.2 step 2D.
110+
{
111+
code: '<template><input type="image" aria-label=" " /></template>',
112+
output: null,
113+
errors: [{ messageId: 'inputImage' }],
114+
},
115+
{
116+
code: '<template><object aria-labelledby="\n\t" ></object></template>',
117+
output: null,
118+
errors: [{ messageId: 'objectMissing' }],
119+
},
120+
{
121+
code: '<template><area href="/" title=" " /></template>',
122+
output: null,
123+
errors: [{ messageId: 'areaMissing' }],
124+
},
109125
{
110126
code: '<template><img src="/test.jpg" /></template>',
111127
output: null,

0 commit comments

Comments
 (0)