Skip to content

Commit 050d2bf

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 050d2bf

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ const EMBER_EVENTS = new Set([
1212
'contextMenu',
1313
'click',
1414
'doubleClick',
15-
'mouseMove',
16-
'mouseEnter',
17-
'mouseLeave',
1815
'focusIn',
1916
'focusOut',
2017
'submit',
@@ -77,10 +74,19 @@ module.exports = {
7774

7875
return {
7976
GlimmerElementNode(node) {
80-
// Only check component invocations (PascalCase)
81-
if (!/^[A-Z]/.test(node.tag)) {
77+
// Only check component invocations. In GTS, dashed tags like <my-button>
78+
// are HTML (imports can't have dashes); lowercase non-dashed tags are
79+
// HTML. Components are PascalCase, @-prefixed args, this.-prefixed
80+
// references, or dot-paths (re-exports).
81+
const isComponent =
82+
/^[A-Z]/.test(node.tag) ||
83+
node.tag.startsWith('@') ||
84+
node.tag.startsWith('this.') ||
85+
node.tag.includes('.');
86+
if (!isComponent) {
8287
return;
8388
}
89+
8490
// Skip built-in Input/Textarea
8591
if (node.tag === 'Input' || node.tag === 'Textarea') {
8692
return;
@@ -98,8 +104,8 @@ module.exports = {
98104
}
99105
const argName = attr.name.slice(1);
100106

101-
// Check ignore config
102-
if (ignoredAttrs.includes(attr.name)) {
107+
// Check ignore config (use bare name without @)
108+
if (ignoredAttrs.includes(argName)) {
103109
continue;
104110
}
105111

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ 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>',
42+
43+
// mouseMove/mouseEnter/mouseLeave are NOT in upstream's event list
44+
'<template><Foo @mouseMove={{this.handleMove}} /></template>',
45+
'<template><Foo @mouseEnter={{this.handleEnter}} /></template>',
46+
'<template><Foo @mouseLeave={{this.handleLeave}} /></template>',
3847
'<template>{{foo}}</template>',
3948
'<template>{{foo onClick=this.handleClick}}</template>',
4049
'<template>{{foo onclick=this.handleClick}}</template>',
@@ -48,11 +57,11 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
4857
// ignore option — angle bracket invocation
4958
{
5059
code: '<template><Foo @click={{this.handleClick}} /></template>',
51-
options: [{ ignore: { Foo: ['@click'] } }],
60+
options: [{ ignore: { Foo: ['click'] } }],
5261
},
5362
{
5463
code: '<template><Foo @click={{this.handleClick}} @submit={{this.handleSubmit}} /></template>',
55-
options: [{ ignore: { Foo: ['@click', '@submit'] } }],
64+
options: [{ ignore: { Foo: ['click', 'submit'] } }],
5665
},
5766

5867
// ignore option — curly invocation
@@ -82,25 +91,33 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
8291
errors: [{ messageId: 'unexpected' }],
8392
},
8493
{
85-
code: `<template>
86-
<CustomButton @mouseEnter={{this.handleHover}} />
87-
</template>`,
94+
code: '<template><Foo @click={{this.handleClick}} /></template>',
8895
output: null,
8996
errors: [{ messageId: 'unexpected' }],
9097
},
91-
9298
{
93-
code: '<template><Foo @click={{this.handleClick}} /></template>',
99+
code: '<template><Foo @keyPress={{this.handleClick}} /></template>',
94100
output: null,
95101
errors: [{ messageId: 'unexpected' }],
96102
},
97103
{
98-
code: '<template><Foo @keyPress={{this.handleClick}} /></template>',
104+
code: '<template><Foo @submit={{this.handleClick}} /></template>',
99105
output: null,
100106
errors: [{ messageId: 'unexpected' }],
101107
},
108+
// Non-PascalCase component forms: this.-prefixed, @-prefixed, dot-path
102109
{
103-
code: '<template><Foo @submit={{this.handleClick}} /></template>',
110+
code: '<template><this.MyComponent @click={{this.handleClick}} /></template>',
111+
output: null,
112+
errors: [{ messageId: 'unexpected' }],
113+
},
114+
{
115+
code: '<template><@someComponent @click={{this.handleClick}} /></template>',
116+
output: null,
117+
errors: [{ messageId: 'unexpected' }],
118+
},
119+
{
120+
code: '<template><ns.Widget @submit={{this.handleSubmit}} /></template>',
104121
output: null,
105122
errors: [{ messageId: 'unexpected' }],
106123
},
@@ -124,14 +141,14 @@ ruleTester.run('template-no-passed-in-event-handlers', rule, {
124141
{
125142
code: '<template><Bar @click={{this.handleClick}} /></template>',
126143
output: null,
127-
options: [{ ignore: { Foo: ['@click'] } }],
144+
options: [{ ignore: { Foo: ['click'] } }],
128145
errors: [{ messageId: 'unexpected' }],
129146
},
130147
// ignore option — only ignores specified attrs (angle bracket)
131148
{
132149
code: '<template><Foo @submit={{this.handleSubmit}} /></template>',
133150
output: null,
134-
options: [{ ignore: { Foo: ['@click'] } }],
151+
options: [{ ignore: { Foo: ['click'] } }],
135152
errors: [{ messageId: 'unexpected' }],
136153
},
137154
// ignore option — only ignores specified component (curly)
@@ -183,11 +200,11 @@ hbsRuleTester.run('template-no-passed-in-event-handlers', rule, {
183200
// ignore option — angle bracket invocation
184201
{
185202
code: '<Foo @click={{this.handleClick}} />',
186-
options: [{ ignore: { Foo: ['@click'] } }],
203+
options: [{ ignore: { Foo: ['click'] } }],
187204
},
188205
{
189206
code: '<Foo @click={{this.handleClick}} @submit={{this.handleSubmit}} />',
190-
options: [{ ignore: { Foo: ['@click', '@submit'] } }],
207+
options: [{ ignore: { Foo: ['click', 'submit'] } }],
191208
},
192209

193210
// ignore option — curly invocation
@@ -266,14 +283,14 @@ hbsRuleTester.run('template-no-passed-in-event-handlers', rule, {
266283
{
267284
code: '<Bar @click={{this.handleClick}} />',
268285
output: null,
269-
options: [{ ignore: { Foo: ['@click'] } }],
286+
options: [{ ignore: { Foo: ['click'] } }],
270287
errors: [{ messageId: 'unexpected' }],
271288
},
272289
// ignore option — only ignores specified attrs (angle bracket)
273290
{
274291
code: '<Foo @submit={{this.handleSubmit}} />',
275292
output: null,
276-
options: [{ ignore: { Foo: ['@click'] } }],
293+
options: [{ ignore: { Foo: ['click'] } }],
277294
errors: [{ messageId: 'unexpected' }],
278295
},
279296
// ignore option — only ignores specified component (curly)

0 commit comments

Comments
 (0)