Skip to content

Commit c4e5929

Browse files
Merge pull request #2736 from johanrd/fix/template-no-yield-only-filter-comments
fix: ignore comment + whitespace nodes in template-no-yield-only
2 parents 7676bb3 + 703bf15 commit c4e5929

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/rules/template-no-yield-only.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
function isEmptyNode(node) {
2+
return (
3+
node.type === 'GlimmerMustacheCommentStatement' ||
4+
node.type === 'GlimmerCommentStatement' ||
5+
(node.type === 'GlimmerTextNode' && !node.chars.trim())
6+
);
7+
}
8+
19
function isYieldOnly(node) {
210
return (
311
node.type === 'GlimmerMustacheStatement' &&
@@ -44,7 +52,8 @@ module.exports = {
4452
? node.body[0].children
4553
: node.body;
4654

47-
if (templateNodes.length === 1 && isYieldOnly(templateNodes[0])) {
55+
const nonEmptyNodes = templateNodes.filter((n) => !isEmptyNode(n));
56+
if (nonEmptyNodes.length === 1 && isYieldOnly(nonEmptyNodes[0])) {
4857
isOnlyYield = true;
4958
}
5059
},

tests/lib/rules/template-no-yield-only.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ const invalidHbs = [
3030
output: null,
3131
errors: [{ messageId: 'noYieldOnly' }],
3232
},
33+
{
34+
code: '{{!-- long-form comment --}}{{yield}}',
35+
output: null,
36+
errors: [{ messageId: 'noYieldOnly' }],
37+
},
38+
{
39+
code: '<!-- html comment -->{{yield}}',
40+
output: null,
41+
errors: [{ messageId: 'noYieldOnly' }],
42+
},
3343
];
3444

3545
function wrapTemplate(entry) {

0 commit comments

Comments
 (0)