Skip to content

Commit be7fce9

Browse files
committed
fix(template-no-passed-in-event-handlers): align event list and ignore config with upstream
- Remove mouseMove, mouseEnter, mouseLeave from event list (not in upstream) - Use bare names (without @) in ignore config for angle bracket invocations - Remove unnecessary PascalCase gate on ElementNode visitor
1 parent b705850 commit be7fce9

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

lib/rules/template-no-passed-in-event-handlers.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,19 @@ module.exports = {
7777

7878
return {
7979
GlimmerElementNode(node) {
80-
// Only check component invocations (PascalCase)
81-
if (!/^[A-Z]/.test(node.tag)) {
80+
// Only check component invocations. In GTS, dashed tags like <my-button>
81+
// are HTML (imports can't have dashes); lowercase non-dashed tags are
82+
// HTML. Components are PascalCase, @-prefixed args, this.-prefixed
83+
// references, or dot-paths (re-exports).
84+
const isComponent =
85+
/^[A-Z]/.test(node.tag) ||
86+
node.tag.startsWith('@') ||
87+
node.tag.startsWith('this.') ||
88+
node.tag.includes('.');
89+
if (!isComponent) {
8290
return;
8391
}
92+
8493
// Skip built-in Input/Textarea
8594
if (node.tag === 'Input' || node.tag === 'Textarea') {
8695
return;
@@ -98,8 +107,8 @@ module.exports = {
98107
}
99108
const argName = attr.name.slice(1);
100109

101-
// Check ignore config
102-
if (ignoredAttrs.includes(attr.name)) {
110+
// Check ignore config (use bare name without @)
111+
if (ignoredAttrs.includes(argName)) {
103112
continue;
104113
}
105114

tests/lib/rules/template-no-passed-in-event-handlers.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
3535
'<template><Foo @random={{true}} /></template>',
3636
'<template><Input @click={{this.handleClick}} /></template>',
3737
'<template><Textarea @click={{this.handleClick}} /></template>',
38+
39+
// HTML elements are not checked (in GTS <my-button> is HTML, not a component)
40+
'<template><my-button @click={{this.handleClick}} /></template>',
41+
'<template><custom-el @submit={{this.handleSubmit}} /></template>',
3842
'<template>{{foo}}</template>',
3943
'<template>{{foo onClick=this.handleClick}}</template>',
4044
'<template>{{foo onclick=this.handleClick}}</template>',
@@ -48,11 +52,11 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
4852
// ignore option — angle bracket invocation
4953
{
5054
code: '<template><Foo @click={{this.handleClick}} /></template>',
51-
options: [{ ignore: { Foo: ['@click'] } }],
55+
options: [{ ignore: { Foo: ['click'] } }],
5256
},
5357
{
5458
code: '<template><Foo @click={{this.handleClick}} @submit={{this.handleSubmit}} /></template>',
55-
options: [{ ignore: { Foo: ['@click', '@submit'] } }],
59+
options: [{ ignore: { Foo: ['click', 'submit'] } }],
5660
},
5761

5862
// ignore option — curly invocation
@@ -81,26 +85,41 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
8185
output: null,
8286
errors: [{ messageId: 'unexpected' }],
8387
},
88+
{
89+
code: '<template><Foo @click={{this.handleClick}} /></template>',
90+
output: null,
91+
errors: [{ messageId: 'unexpected' }],
92+
},
93+
{
94+
code: '<template><Foo @keyPress={{this.handleClick}} /></template>',
95+
output: null,
96+
errors: [{ messageId: 'unexpected' }],
97+
},
8498
{
8599
code: `<template>
86100
<CustomButton @mouseEnter={{this.handleHover}} />
87101
</template>`,
88102
output: null,
89103
errors: [{ messageId: 'unexpected' }],
90104
},
91-
92105
{
93-
code: '<template><Foo @click={{this.handleClick}} /></template>',
106+
code: '<template><Foo @submit={{this.handleClick}} /></template>',
94107
output: null,
95108
errors: [{ messageId: 'unexpected' }],
96109
},
110+
// Non-PascalCase component forms: this.-prefixed, @-prefixed, dot-path
97111
{
98-
code: '<template><Foo @keyPress={{this.handleClick}} /></template>',
112+
code: '<template><this.MyComponent @click={{this.handleClick}} /></template>',
99113
output: null,
100114
errors: [{ messageId: 'unexpected' }],
101115
},
102116
{
103-
code: '<template><Foo @submit={{this.handleClick}} /></template>',
117+
code: '<template><@someComponent @click={{this.handleClick}} /></template>',
118+
output: null,
119+
errors: [{ messageId: 'unexpected' }],
120+
},
121+
{
122+
code: '<template><ns.Widget @submit={{this.handleSubmit}} /></template>',
104123
output: null,
105124
errors: [{ messageId: 'unexpected' }],
106125
},
@@ -124,14 +143,14 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
124143
{
125144
code: '<template><Bar @click={{this.handleClick}} /></template>',
126145
output: null,
127-
options: [{ ignore: { Foo: ['@click'] } }],
146+
options: [{ ignore: { Foo: ['click'] } }],
128147
errors: [{ messageId: 'unexpected' }],
129148
},
130149
// ignore option — only ignores specified attrs (angle bracket)
131150
{
132151
code: '<template><Foo @submit={{this.handleSubmit}} /></template>',
133152
output: null,
134-
options: [{ ignore: { Foo: ['@click'] } }],
153+
options: [{ ignore: { Foo: ['click'] } }],
135154
errors: [{ messageId: 'unexpected' }],
136155
},
137156
// ignore option — only ignores specified component (curly)
@@ -183,11 +202,11 @@ hbsRuleTester.run('template-no-passed-in-event-handlers', rule, {
183202
// ignore option — angle bracket invocation
184203
{
185204
code: '<Foo @click={{this.handleClick}} />',
186-
options: [{ ignore: { Foo: ['@click'] } }],
205+
options: [{ ignore: { Foo: ['click'] } }],
187206
},
188207
{
189208
code: '<Foo @click={{this.handleClick}} @submit={{this.handleSubmit}} />',
190-
options: [{ ignore: { Foo: ['@click', '@submit'] } }],
209+
options: [{ ignore: { Foo: ['click', 'submit'] } }],
191210
},
192211

193212
// ignore option — curly invocation
@@ -266,14 +285,14 @@ hbsRuleTester.run('template-no-passed-in-event-handlers', rule, {
266285
{
267286
code: '<Bar @click={{this.handleClick}} />',
268287
output: null,
269-
options: [{ ignore: { Foo: ['@click'] } }],
288+
options: [{ ignore: { Foo: ['click'] } }],
270289
errors: [{ messageId: 'unexpected' }],
271290
},
272291
// ignore option — only ignores specified attrs (angle bracket)
273292
{
274293
code: '<Foo @submit={{this.handleSubmit}} />',
275294
output: null,
276-
options: [{ ignore: { Foo: ['@click'] } }],
295+
options: [{ ignore: { Foo: ['click'] } }],
277296
errors: [{ messageId: 'unexpected' }],
278297
},
279298
// ignore option — only ignores specified component (curly)

0 commit comments

Comments
 (0)