Skip to content

Commit 0d355e2

Browse files
committed
fix(template-no-attrs-in-components): also flag this.attrs.*
In the Glimmer AST, `this.attrs.foo` has parts[0] === 'attrs' (this is the receiver, not a part), so switching from original.startsWith('attrs.') to parts[0] === 'attrs' matches upstream and correctly flags both bare attrs.* and this.attrs.* — both are pre-Octane @ember/component patterns.
1 parent 5c4bd3e commit 0d355e2

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

lib/rules/template-no-attrs-in-components.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ module.exports = {
2929
}
3030
return {
3131
GlimmerPathExpression(node) {
32-
const original = node.original;
33-
if (typeof original !== 'string') {
34-
return;
35-
}
36-
// Flag bare `attrs` or `attrs.<something>` (pre-Octane args-leakage).
37-
// Do NOT flag `this.attrs.*` — that is a different (non-existent) API.
38-
if (original === 'attrs' || original.startsWith('attrs.')) {
32+
// Flag `attrs.*` and `this.attrs.*` — both are pre-Octane args-leakage
33+
// patterns from @ember/component. In the Glimmer AST, `this.attrs.foo`
34+
// has parts[0] === 'attrs' (this is the receiver, not a part).
35+
if (node.parts && node.parts[0] === 'attrs') {
3936
context.report({ node, messageId: 'noAttrs' });
4037
}
4138
},

tests/lib/rules/template-no-attrs-in-components.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ ruleTester.run('template-no-attrs-in-components', rule, {
1717
filename: 'app/templates/application.hbs',
1818
code: '<template>{{this.value}}</template>',
1919
},
20-
// `this.attrs.*` is not a real Ember API, but it is NOT what this rule
21-
// targets — only bare `attrs.*` is flagged. So outside of a component
22-
// template, `this.attrs.*` should not be flagged.
20+
// `this.attrs.*` outside a component template — not flagged (path gate).
2321
{
2422
filename: 'app/templates/application.hbs',
2523
code: '<template>{{this.attrs.foo}}</template>',
@@ -38,11 +36,6 @@ ruleTester.run('template-no-attrs-in-components', rule, {
3836
filename: 'app/templates/components/foo.hbs',
3937
code: '<template>{{this.value}}</template>',
4038
},
41-
// This rule does NOT flag `this.attrs.*`; only bare `attrs.*`.
42-
{
43-
filename: 'app/templates/components/foo.hbs',
44-
code: '<template>{{this.attrs.foo}}</template>',
45-
},
4639
// Pod-style components path matches the gate, but no `attrs` usage.
4740
{
4841
filename: 'app/components/foo/template.hbs',
@@ -90,5 +83,12 @@ ruleTester.run('template-no-attrs-in-components', rule, {
9083
output: null,
9184
errors: [{ messageId: 'noAttrs' }],
9285
},
86+
// `this.attrs.*` inside a component template — flagged (real @ember/component API).
87+
{
88+
filename: 'app/templates/components/foo.hbs',
89+
code: '<template>{{this.attrs.foo}}</template>',
90+
output: null,
91+
errors: [{ messageId: 'noAttrs' }],
92+
},
9393
],
9494
});

0 commit comments

Comments
 (0)