Skip to content

Commit a02b3e9

Browse files
committed
fix(template-no-empty-headings): recognize quoted-mustache aria-hidden
`isAriaHiddenTruthy` previously only handled raw TextNode and bare MustacheStatement attribute values. The quoted-mustache form `aria-hidden="{{true}}"` produces a `GlimmerConcatStatement` with a single mustache part — resolve that case by descending into the single static-literal part, mirroring the pattern established in template-no-aria-hidden-focusable. Leans toward "truthy" only on literal true / empty / bare-valueless to match the rule's doc-stated ethos of fewer false positives.
1 parent 16ca450 commit a02b3e9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

lib/rules/template-no-empty-headings.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,31 @@ function isAriaHiddenTruthy(attr) {
3939
return value.path.value.toLowerCase() === 'true';
4040
}
4141
}
42+
if (value.type === 'GlimmerConcatStatement') {
43+
// Quoted-mustache form like aria-hidden="{{true}}" or aria-hidden="{{x}}".
44+
// Only resolve when the concat is a single static-literal part; any
45+
// dynamic path makes the runtime value unknown. Lean toward "truthy"
46+
// only on literal `true` / empty-literal / bare-valueless to stay aligned
47+
// with the doc-stated ethos (fewer false positives — don't flag headings
48+
// the author has intentionally decorated with aria-hidden).
49+
const parts = value.parts || [];
50+
if (parts.length === 1) {
51+
const only = parts[0];
52+
if (only.type === 'GlimmerMustacheStatement' && only.path) {
53+
if (only.path.type === 'GlimmerBooleanLiteral') {
54+
return only.path.value === true;
55+
}
56+
if (only.path.type === 'GlimmerStringLiteral') {
57+
return only.path.value.toLowerCase() === 'true';
58+
}
59+
}
60+
if (only.type === 'GlimmerTextNode') {
61+
const chars = only.chars.toLowerCase();
62+
return chars === '' || chars === 'true';
63+
}
64+
}
65+
return false;
66+
}
4267
return false;
4368
}
4469

0 commit comments

Comments
 (0)