Skip to content

Commit 130773d

Browse files
committed
Fix template-no-empty-headings: detect this./@/dot-path component children
GTS component invocations can appear as <this.Foo>, <@foo>, or <ns.Foo> in addition to PascalCase. The rule's isComponent() check was too narrow, so children of headings using these forms were not recognized as content and the heading was falsely flagged as empty.
1 parent b705850 commit 130773d

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ function isComponent(node) {
1919
return false;
2020
}
2121
const tag = node.tag;
22-
return /^[A-Z]/.test(tag) || tag.includes('::');
22+
// PascalCase (<MyComponent>), namespaced (<Foo::Bar>), this.-prefixed
23+
// (<this.Component>), arg-prefixed (<@component>), or dot-path (<ns.Widget>)
24+
return (
25+
/^[A-Z]/.test(tag) ||
26+
tag.includes('::') ||
27+
tag.startsWith('this.') ||
28+
tag.startsWith('@') ||
29+
tag.includes('.')
30+
);
2331
}
2432

2533
function isTextEmpty(text) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ ruleTester.run('template-no-empty-headings', rule, {
3838
'<template><h2><div><span>{{@title}}</span></div></h2></template>',
3939
'<template><h2><span>Some text{{@title}}</span></h2></template>',
4040
'<template><h2><span><div></div>{{@title}}</span></h2></template>',
41+
42+
// Non-PascalCase component forms count as accessible content
43+
'<template><h1><this.Heading /></h1></template>',
44+
'<template><h2><@heading /></h2></template>',
45+
'<template><h3><ns.Heading /></h3></template>',
4146
],
4247
invalid: [
4348
{

0 commit comments

Comments
 (0)