Skip to content

Commit e0b77ba

Browse files
committed
robust check
1 parent 3a097ee commit e0b77ba

File tree

2 files changed

+371
-1
lines changed

2 files changed

+371
-1
lines changed

packages/eslint-plugin-svelte/src/rules/no-not-function-handler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AST } from 'svelte-eslint-parser';
22
import type { TSESTree } from '@typescript-eslint/types';
33
import { createRule } from '../utils/index.js';
44
import { findVariable } from '../utils/ast-utils.js';
5+
import { EVENT_NAMES } from '../utils/events.js';
56

67
const PHRASES = {
78
ObjectExpression: 'object',
@@ -97,7 +98,7 @@ export default createRule('no-not-function-handler', {
9798
verify(node.expression);
9899
},
99100
SvelteAttribute(node) {
100-
if (node.key.type === 'SvelteName' && node.key.name.startsWith('on')) {
101+
if (node.key.type === 'SvelteName' && EVENT_NAMES.includes(node.key.name)) {
101102
const { value } = node;
102103
if (Array.isArray(value)) {
103104
for (const v of value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
// see: https://github.com/sveltejs/svelte/blob/a129592e5b248a734a68da6e9028941803a3d063/packages/svelte/elements.d.ts#L83
2+
export const EVENT_NAMES: string[] = [
3+
// Clipboard Events
4+
'on:copy',
5+
'oncopy',
6+
'oncopycapture',
7+
'on:cut',
8+
'oncut',
9+
'oncutcapture',
10+
'on:paste',
11+
'onpaste',
12+
'onpastecapture',
13+
14+
// Composition Events
15+
'on:compositionend',
16+
'oncompositionend',
17+
'oncompositionendcapture',
18+
'on:compositionstart',
19+
'oncompositionstart',
20+
'oncompositionstartcapture',
21+
'on:compositionupdate',
22+
'oncompositionupdate',
23+
'oncompositionupdatecapture',
24+
25+
// Focus Events
26+
'on:focus',
27+
'onfocus',
28+
'onfocuscapture',
29+
'on:focusin',
30+
'onfocusin',
31+
'onfocusincapture',
32+
'on:focusout',
33+
'onfocusout',
34+
'onfocusoutcapture',
35+
'on:blur',
36+
'onblur',
37+
'onblurcapture',
38+
39+
// Form Events
40+
'on:change',
41+
'onchange',
42+
'onchangecapture',
43+
'on:beforeinput',
44+
'onbeforeinput',
45+
'onbeforeinputcapture',
46+
// oninput can be either an InputEvent or an Event, depending on the target element (input, textarea etc).
47+
'on:input',
48+
'oninput',
49+
'oninputcapture',
50+
'on:reset',
51+
'onreset',
52+
'onresetcapture',
53+
'on:submit',
54+
'onsubmit',
55+
'onsubmitcapture',
56+
'on:invalid',
57+
'oninvalid',
58+
'oninvalidcapture',
59+
'on:formdata',
60+
'onformdata',
61+
'onformdatacapture',
62+
63+
// Image Events
64+
'on:load',
65+
'onload',
66+
'onloadcapture',
67+
'on:error',
68+
'onerror',
69+
'onerrorcapture',
70+
71+
// Popover Events
72+
'on:beforetoggle',
73+
'onbeforetoggle',
74+
'onbeforetogglecapture',
75+
'on:toggle',
76+
'ontoggle',
77+
'ontogglecapture',
78+
79+
// Content visibility Events
80+
'on:contentvisibilityautostatechange',
81+
'oncontentvisibilityautostatechange',
82+
'oncontentvisibilityautostatechangecapture',
83+
// Keyboard Events
84+
'on:keydown',
85+
'onkeydown',
86+
'onkeydowncapture',
87+
'on:keypress',
88+
'onkeypress',
89+
'onkeypresscapture',
90+
'on:keyup',
91+
'onkeyup',
92+
'onkeyupcapture',
93+
94+
// Media Events
95+
'on:abort',
96+
'onabort',
97+
'onabortcapture',
98+
'on:canplay',
99+
'oncanplay',
100+
'oncanplaycapture',
101+
'on:canplaythrough',
102+
'oncanplaythrough',
103+
'oncanplaythroughcapture',
104+
'on:cuechange',
105+
'oncuechange',
106+
'oncuechangecapture',
107+
'on:durationchange',
108+
'ondurationchange',
109+
'ondurationchangecapture',
110+
'on:emptied',
111+
'onemptied',
112+
'onemptiedcapture',
113+
'on:encrypted',
114+
'onencrypted',
115+
'onencryptedcapture',
116+
'on:ended',
117+
'onended',
118+
'onendedcapture',
119+
'on:loadeddata',
120+
'onloadeddata',
121+
'onloadeddatacapture',
122+
'on:loadedmetadata',
123+
'onloadedmetadata',
124+
'onloadedmetadatacapture',
125+
'on:loadstart',
126+
'onloadstart',
127+
'onloadstartcapture',
128+
'on:pause',
129+
'onpause',
130+
'onpausecapture',
131+
'on:play',
132+
'onplay',
133+
'onplaycapture',
134+
'on:playing',
135+
'onplaying',
136+
'onplayingcapture',
137+
'on:progress',
138+
'onprogress',
139+
'onprogresscapture',
140+
'on:ratechange',
141+
'onratechange',
142+
'onratechangecapture',
143+
'on:seeked',
144+
'onseeked',
145+
'onseekedcapture',
146+
'on:seeking',
147+
'onseeking',
148+
'onseekingcapture',
149+
'on:stalled',
150+
'onstalled',
151+
'onstalledcapture',
152+
'on:suspend',
153+
'onsuspend',
154+
'onsuspendcapture',
155+
'on:timeupdate',
156+
'ontimeupdate',
157+
'ontimeupdatecapture',
158+
'on:volumechange',
159+
'onvolumechange',
160+
'onvolumechangecapture',
161+
'on:waiting',
162+
'onwaiting',
163+
'onwaitingcapture',
164+
165+
// MouseEvents
166+
'on:auxclick',
167+
'onauxclick',
168+
'onauxclickcapture',
169+
'on:click',
170+
'onclick',
171+
'onclickcapture',
172+
'on:contextmenu',
173+
'oncontextmenu',
174+
'oncontextmenucapture',
175+
'on:dblclick',
176+
'ondblclick',
177+
'ondblclickcapture',
178+
'on:drag',
179+
'ondrag',
180+
'ondragcapture',
181+
'on:dragend',
182+
'ondragend',
183+
'ondragendcapture',
184+
'on:dragenter',
185+
'ondragenter',
186+
'ondragentercapture',
187+
'on:dragexit',
188+
'ondragexit',
189+
'ondragexitcapture',
190+
'on:dragleave',
191+
'ondragleave',
192+
'ondragleavecapture',
193+
'on:dragover',
194+
'ondragover',
195+
'ondragovercapture',
196+
'on:dragstart',
197+
'ondragstart',
198+
'ondragstartcapture',
199+
'on:drop',
200+
'ondrop',
201+
'ondropcapture',
202+
'on:mousedown',
203+
'onmousedown',
204+
'onmousedowncapture',
205+
'on:mouseenter',
206+
'onmouseenter',
207+
'on:mouseleave',
208+
'onmouseleave',
209+
'on:mousemove',
210+
'onmousemove',
211+
'onmousemovecapture',
212+
'on:mouseout',
213+
'onmouseout',
214+
'onmouseoutcapture',
215+
'on:mouseover',
216+
'onmouseover',
217+
'onmouseovercapture',
218+
'on:mouseup',
219+
'onmouseup',
220+
'onmouseupcapture',
221+
222+
// Selection Events
223+
'on:select',
224+
'onselect',
225+
'onselectcapture',
226+
'on:selectionchange',
227+
'onselectionchange',
228+
'onselectionchangecapture',
229+
'on:selectstart',
230+
'onselectstart',
231+
'onselectstartcapture',
232+
233+
// Touch Events
234+
'on:touchcancel',
235+
'ontouchcancel',
236+
'ontouchcancelcapture',
237+
'on:touchend',
238+
'ontouchend',
239+
'ontouchendcapture',
240+
'on:touchmove',
241+
'ontouchmove',
242+
'ontouchmovecapture',
243+
'on:touchstart',
244+
'ontouchstart',
245+
'ontouchstartcapture',
246+
247+
// Pointer Events
248+
'on:gotpointercapture',
249+
'ongotpointercapture',
250+
'ongotpointercapturecapture',
251+
'on:pointercancel',
252+
'onpointercancel',
253+
'onpointercancelcapture',
254+
'on:pointerdown',
255+
'onpointerdown',
256+
'onpointerdowncapture',
257+
'on:pointerenter',
258+
'onpointerenter',
259+
'onpointerentercapture',
260+
'on:pointerleave',
261+
'onpointerleave',
262+
'onpointerleavecapture',
263+
'on:pointermove',
264+
'onpointermove',
265+
'onpointermovecapture',
266+
'on:pointerout',
267+
'onpointerout',
268+
'onpointeroutcapture',
269+
'on:pointerover',
270+
'onpointerover',
271+
'onpointerovercapture',
272+
'on:pointerup',
273+
'onpointerup',
274+
'onpointerupcapture',
275+
'on:lostpointercapture',
276+
'onlostpointercapture',
277+
'onlostpointercapturecapture',
278+
279+
// Gamepad Events
280+
'on:gamepadconnected',
281+
'ongamepadconnected',
282+
'on:gamepaddisconnected',
283+
'ongamepaddisconnected',
284+
285+
// UI Events
286+
'on:scroll',
287+
'onscroll',
288+
'onscrollcapture',
289+
'on:scrollend',
290+
'onscrollend',
291+
'onscrollendcapture',
292+
'on:resize',
293+
'onresize',
294+
'onresizecapture',
295+
296+
// Wheel Events
297+
'on:wheel',
298+
'onwheel',
299+
'onwheelcapture',
300+
301+
// Animation Events
302+
'on:animationstart',
303+
'onanimationstart',
304+
'onanimationstartcapture',
305+
'on:animationend',
306+
'onanimationend',
307+
'onanimationendcapture',
308+
'on:animationiteration',
309+
'onanimationiteration',
310+
'onanimationiterationcapture',
311+
312+
// Transition Events
313+
'on:transitionstart',
314+
'ontransitionstart',
315+
'ontransitionstartcapture',
316+
'on:transitionrun',
317+
'ontransitionrun',
318+
'ontransitionruncapture',
319+
'on:transitionend',
320+
'ontransitionend',
321+
'ontransitionendcapture',
322+
'on:transitioncancel',
323+
'ontransitioncancel',
324+
'ontransitioncancelcapture',
325+
326+
// Svelte Transition Events
327+
'on:outrostart',
328+
'onoutrostart',
329+
'onoutrostartcapture',
330+
'on:outroend',
331+
'onoutroend',
332+
'onoutroendcapture',
333+
'on:introstart',
334+
'onintrostart',
335+
'onintrostartcapture',
336+
'on:introend',
337+
'onintroend',
338+
'onintroendcapture',
339+
340+
// Message Events
341+
'on:message',
342+
'onmessage',
343+
'onmessagecapture',
344+
'on:messageerror',
345+
'onmessageerror',
346+
'onmessageerrorcapture',
347+
348+
// Document Events
349+
'on:visibilitychange',
350+
'onvisibilitychange',
351+
'onvisibilitychangecapture',
352+
353+
// Global Events
354+
'on:beforematch',
355+
'onbeforematch',
356+
'onbeforematchcapture',
357+
'on:cancel',
358+
'oncancel',
359+
'oncancelcapture',
360+
'on:close',
361+
'onclose',
362+
'onclosecapture',
363+
'on:fullscreenchange',
364+
'onfullscreenchange',
365+
'onfullscreenchangecapture',
366+
'on:fullscreenerror',
367+
'onfullscreenerror',
368+
'onfullscreenerrorcapture'
369+
] as const;

0 commit comments

Comments
 (0)