Skip to content

Commit 511b615

Browse files
committed
Fix template-no-obsolete-elements: track element-level block params
The rule suppressed obsolete-element reports when the tag name shadows a block param from a GlimmerBlockStatement (e.g. {{#let (...) as |marquee|}}). It did not track element-level block params (<Comp as |marquee|>), so inside an angle-bracket component the shadowing was ignored and the tag was falsely reported. Push element block params on enter and pop on exit, mirroring the existing GlimmerBlockStatement handling.
1 parent b705850 commit 511b615

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/rules/template-no-obsolete-elements.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,21 @@ module.exports = {
6464
}
6565
},
6666
GlimmerElementNode(node) {
67-
if (blockParamsInScope.includes(node.tag)) {
68-
return;
69-
}
70-
if (obsolete.has(node.tag)) {
67+
// Push element-level block params (e.g. <Comp as |param|>) before
68+
// checking children. Pop on exit.
69+
const elementParams = node.blockParams || [];
70+
blockParamsInScope.push(...elementParams);
71+
72+
if (!blockParamsInScope.includes(node.tag) && obsolete.has(node.tag)) {
7173
context.report({ node, messageId: 'obsolete', data: { element: node.tag } });
7274
}
7375
},
76+
'GlimmerElementNode:exit'(node) {
77+
const elementParams = node.blockParams || [];
78+
for (let i = 0; i < elementParams.length; i++) {
79+
blockParamsInScope.pop();
80+
}
81+
},
7482
};
7583
},
7684
};

tests/lib/rules/template-no-obsolete-elements.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ ruleTester.run('template-no-obsolete-elements', rule, {
1111
`<template>{{#let (component 'whatever-here') as |plaintext|}}
1212
<plaintext />
1313
{{/let}}</template>`,
14+
// Element-level block params (<Comp as |...|>) are now tracked
15+
'<template><Comp as |plaintext|><plaintext /></Comp></template>',
16+
'<template><Outer as |marquee|><marquee /></Outer></template>',
1417
],
1518
invalid: [
1619
{

0 commit comments

Comments
 (0)