Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions lib/rules/template-no-empty-headings.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
const HEADINGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);

function isAriaHiddenTruthy(attr) {
if (!attr) {
return false;
}
const value = attr.value;
// Valueless or empty-string attribute — <h1 aria-hidden />. Per HTML boolean
// attribute semantics (and jsx-a11y/vue-a11y convention), presence = truthy.
if (!value || (value.type === 'GlimmerTextNode' && value.chars === '')) {
return true;
}
if (value.type === 'GlimmerTextNode') {
return value.chars === 'true';
}
if (value.type === 'GlimmerMustacheStatement' && value.path) {
if (value.path.type === 'GlimmerBooleanLiteral') {
return value.path.value === true;
}
if (value.path.type === 'GlimmerStringLiteral') {
return value.path.value === 'true';
}
}
return false;
}

function isHidden(node) {
if (!node.attributes) {
return false;
}
if (node.attributes.some((a) => a.name === 'hidden')) {
return true;
}
const ariaHidden = node.attributes.find((a) => a.name === 'aria-hidden');
if (ariaHidden?.value?.type === 'GlimmerTextNode' && ariaHidden.value.chars === 'true') {
return true;
}
return false;
return isAriaHiddenTruthy(node.attributes.find((a) => a.name === 'aria-hidden'));
}

function isComponent(node) {
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/template-no-empty-headings.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ ruleTester.run('template-no-empty-headings', rule, {
'<template><h1><this.Heading /></h1></template>',
'<template><h2><@heading /></h2></template>',
'<template><h3><ns.Heading /></h3></template>',

// aria-hidden as a boolean / valueless / empty / mustache attribute — all
// should exempt the heading (aligns with jsx-a11y / vue-a11y treatment of
// boolean HTML attributes).
'<template><h1 aria-hidden></h1></template>',
'<template><h1 aria-hidden=""></h1></template>',
'<template><h1 aria-hidden={{true}}></h1></template>',
'<template><h1 aria-hidden="true">Visible to sighted only</h1></template>',
],
invalid: [
{
Expand Down
Loading