Skip to content

Commit 37b5777

Browse files
Merge pull request #2636 from tcjr/unused-block-attr
Fix rule: ember/template-no-unused-block-params
2 parents d7465c1 + 05ae98f commit 37b5777

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/rules/template-no-unused-block-params.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ function collectChildNodes(n) {
2424
if (n.children) {
2525
children.push(...n.children);
2626
}
27+
// GlimmerPathExpression also has 'parts', so make sure we're not treating
28+
// concat'd path string parts as AST nodes.
29+
if (n.type === 'GlimmerConcatStatement' && n.parts) {
30+
children.push(...n.parts);
31+
}
2732
return children;
2833
}
2934

tests/lib/rules/template-no-unused-block-params.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ const validHbs = [
1111
'{{#each cats as |cat|}}{{meow cat}}{{/each}}',
1212
'{{#each cats as |cat index|}}{{index}}{{/each}}',
1313
'{{#each cats as |cat index|}}{{#each cat.lives as |life|}}{{index}}: {{life}}{{/each}}{{/each}}',
14+
`
15+
{{#each cats as |cat|}}
16+
<div data-cat-name={{cat.name}}></div>
17+
{{/each}}
18+
`,
19+
`
20+
{{#each cats as |cat|}}
21+
<div class="cat {{cat.name}}"></div>
22+
{{/each}}
23+
`,
24+
`
25+
{{#each cats as |cat|}}
26+
<div class="cat {{if (isFavorite cat.name favoriteCatNames) 'favorite'}}"></div>
27+
{{/each}}
28+
`,
1429
`
1530
<MyComponent @model={{this.model}} as |param|>
1631
{{! template-lint-disable }}
@@ -98,6 +113,16 @@ const invalidHbs = [
98113
output: null,
99114
errors: [{ messageId: 'unusedBlockParam', data: { param: 'life' } }],
100115
},
116+
{
117+
code: '{{#each cats as |cat|}}plain cat text{{/each}}',
118+
output: null,
119+
errors: [{ messageId: 'unusedBlockParam', data: { param: 'cat' } }],
120+
},
121+
{
122+
code: '{{#each cats as |cat|}}{{a.different.cat}}{{/each}}',
123+
output: null,
124+
errors: [{ messageId: 'unusedBlockParam', data: { param: 'cat' } }],
125+
},
101126
];
102127

103128
function wrapTemplate(entry) {

0 commit comments

Comments
 (0)