Skip to content
Merged
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
11 changes: 10 additions & 1 deletion lib/rules/template-no-yield-only.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function isEmptyNode(node) {
return (
node.type === 'GlimmerMustacheCommentStatement' ||
node.type === 'GlimmerCommentStatement' ||
(node.type === 'GlimmerTextNode' && !node.chars.trim())
);
}

function isYieldOnly(node) {
return (
node.type === 'GlimmerMustacheStatement' &&
Expand Down Expand Up @@ -44,7 +52,8 @@ module.exports = {
? node.body[0].children
: node.body;

if (templateNodes.length === 1 && isYieldOnly(templateNodes[0])) {
const nonEmptyNodes = templateNodes.filter((n) => !isEmptyNode(n));
if (nonEmptyNodes.length === 1 && isYieldOnly(nonEmptyNodes[0])) {
isOnlyYield = true;
}
},
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/template-no-yield-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ const invalidHbs = [
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '{{!-- long-form comment --}}{{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '<!-- html comment -->{{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
];

function wrapTemplate(entry) {
Expand Down
Loading