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
5 changes: 5 additions & 0 deletions lib/rules/template-no-unused-block-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function collectChildNodes(n) {
if (n.children) {
children.push(...n.children);
}
// GlimmerPathExpression also has 'parts', so make sure we're not treating
// concat'd path string parts as AST nodes.
if (n.type === 'GlimmerConcatStatement' && n.parts) {
children.push(...n.parts);
}
return children;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/template-no-unused-block-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const validHbs = [
'{{#each cats as |cat|}}{{meow cat}}{{/each}}',
'{{#each cats as |cat index|}}{{index}}{{/each}}',
'{{#each cats as |cat index|}}{{#each cat.lives as |life|}}{{index}}: {{life}}{{/each}}{{/each}}',
`
{{#each cats as |cat|}}
<div data-cat-name={{cat.name}}></div>
{{/each}}
`,
`
{{#each cats as |cat|}}
<div class="cat {{cat.name}}"></div>
{{/each}}
`,
`
{{#each cats as |cat|}}
<div class="cat {{if (isFavorite cat.name favoriteCatNames) 'favorite'}}"></div>
{{/each}}
`,
`
<MyComponent @model={{this.model}} as |param|>
{{! template-lint-disable }}
Expand Down Expand Up @@ -98,6 +113,16 @@ const invalidHbs = [
output: null,
errors: [{ messageId: 'unusedBlockParam', data: { param: 'life' } }],
},
{
code: '{{#each cats as |cat|}}plain cat text{{/each}}',
output: null,
errors: [{ messageId: 'unusedBlockParam', data: { param: 'cat' } }],
},
{
code: '{{#each cats as |cat|}}{{a.different.cat}}{{/each}}',
output: null,
errors: [{ messageId: 'unusedBlockParam', data: { param: 'cat' } }],
},
];

function wrapTemplate(entry) {
Expand Down
Loading