Skip to content

Commit 029c2c0

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 029c2c0

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,22 @@ module.exports = {
6464
}
6565
},
6666
GlimmerElementNode(node) {
67-
if (blockParamsInScope.includes(node.tag)) {
68-
return;
69-
}
70-
if (obsolete.has(node.tag)) {
67+
// Check the element's own tag before pushing its block params, so an
68+
// element's own params don't shadow its own tag name (e.g.
69+
// `<marquee as |marquee|>` should still flag the outer <marquee>).
70+
if (!blockParamsInScope.includes(node.tag) && obsolete.has(node.tag)) {
7171
context.report({ node, messageId: 'obsolete', data: { element: node.tag } });
7272
}
73+
// Element-level block params (e.g. `<Comp as |param|>`) are scoped to
74+
// the children, so push them after the obsolete check. Pop on exit.
75+
const elementParams = node.blockParams || [];
76+
blockParamsInScope.push(...elementParams);
77+
},
78+
'GlimmerElementNode:exit'(node) {
79+
const elementParams = node.blockParams || [];
80+
for (let i = 0; i < elementParams.length; i++) {
81+
blockParamsInScope.pop();
82+
}
7383
},
7484
};
7585
},

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ 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
{
1720
code: '<template><marquee></marquee></template>',
1821
output: null,
1922
errors: [{ messageId: 'obsolete' }],
2023
},
24+
// Element's own block params must not shadow its own tag name.
25+
{
26+
code: '<template><marquee as |marquee|></marquee></template>',
27+
output: null,
28+
errors: [{ messageId: 'obsolete', data: { element: 'marquee' } }],
29+
},
2130
],
2231
});
2332

0 commit comments

Comments
 (0)