Skip to content

Commit 33446a6

Browse files
committed
fix(template-no-attrs-in-components): support co-located templates, broaden test coverage
Add /components/ to the path gate regex to catch Octane co-located templates (app/components/foo.hbs) which the previous pattern missed (cf. ember-template-lint#1445). Add invalid test cases for attrs in attribute value, block helper, and hash pair positions, and for the co-located path pattern.
1 parent 0d355e2 commit 33446a6

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// Matches traditional, pod, ui/components, and -components/ paths.
2+
// Also matches Octane co-located templates (app/components/foo.hbs) via
3+
// /components/ — cf. ember-template-lint#1445.
14
const COMPONENT_TEMPLATE_REGEX = new RegExp(
2-
'templates/components|components/.*/template|ui/components|-components/'
5+
'templates/components|components/.*/template|ui/components|-components/|/components/'
36
);
47

58
/** @type {import('eslint').Rule.RuleModule} */

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ ruleTester.run('template-no-attrs-in-components', rule, {
4646
filename: 'app/ui-components/foo.hbs',
4747
code: '<template>{{@value}}</template>',
4848
},
49+
// Octane co-located template — non-attrs path is fine.
50+
{
51+
filename: 'app/components/foo.hbs',
52+
code: '<template>{{@value}}</template>',
53+
},
4954
],
5055
invalid: [
5156
// Bare `attrs.*` inside `templates/components/` — flagged.
@@ -90,5 +95,33 @@ ruleTester.run('template-no-attrs-in-components', rule, {
9095
output: null,
9196
errors: [{ messageId: 'noAttrs' }],
9297
},
98+
// attrs in attribute value position.
99+
{
100+
filename: 'app/templates/components/foo.hbs',
101+
code: '<template><div class={{attrs.foo}}></div></template>',
102+
output: null,
103+
errors: [{ messageId: 'noAttrs' }],
104+
},
105+
// attrs in block helper condition.
106+
{
107+
filename: 'app/templates/components/foo.hbs',
108+
code: '<template>{{#if attrs.foo}}bar{{/if}}</template>',
109+
output: null,
110+
errors: [{ messageId: 'noAttrs' }],
111+
},
112+
// attrs as hash pair value.
113+
{
114+
filename: 'app/templates/components/foo.hbs',
115+
code: '<template>{{bar foo=attrs.foo}}</template>',
116+
output: null,
117+
errors: [{ messageId: 'noAttrs' }],
118+
},
119+
// Octane co-located template (app/components/foo.hbs) — flagged.
120+
{
121+
filename: 'app/components/foo.hbs',
122+
code: '<template>{{attrs.foo}}</template>',
123+
output: null,
124+
errors: [{ messageId: 'noAttrs' }],
125+
},
93126
],
94127
});

0 commit comments

Comments
 (0)