diff --git a/lib/rules/template-no-yield-only.js b/lib/rules/template-no-yield-only.js index 76d859be8d..b4b423b662 100644 --- a/lib/rules/template-no-yield-only.js +++ b/lib/rules/template-no-yield-only.js @@ -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' && @@ -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; } }, diff --git a/tests/lib/rules/template-no-yield-only.js b/tests/lib/rules/template-no-yield-only.js index 9129c00828..cfb3fc9797 100644 --- a/tests/lib/rules/template-no-yield-only.js +++ b/tests/lib/rules/template-no-yield-only.js @@ -30,6 +30,16 @@ const invalidHbs = [ output: null, errors: [{ messageId: 'noYieldOnly' }], }, + { + code: '{{!-- long-form comment --}}{{yield}}', + output: null, + errors: [{ messageId: 'noYieldOnly' }], + }, + { + code: '{{yield}}', + output: null, + errors: [{ messageId: 'noYieldOnly' }], + }, ]; function wrapTemplate(entry) {