Skip to content

Commit 0ef0f99

Browse files
authored
feat: add Svelte 5 support to no-not-function-handler (#1013)
1 parent 06c2887 commit 0ef0f99

18 files changed

+472
-4
lines changed

.changeset/brown-dots-change.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': minor
3+
---
4+
5+
feat: add Svelte 5 support to `no-not-function-handler`

docs/rules/no-not-function-handler.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ If you use a non-function value for the event handler, it event handler will not
2929
</script>
3030
3131
<!-- ✓ GOOD -->
32-
<button on:click={foo} />
32+
<button onclick={foo} />
3333
<button
34-
on:click={() => {
34+
onclick={() => {
3535
/* */
3636
}}
3737
/>
3838
3939
<!-- ✗ BAD -->
40-
<button on:click={{ foo }} />
41-
<button on:click={bar} />
40+
<button onclick={{ foo }} />
41+
<button onclick={bar} />
4242
```
4343

4444
## :wrench: Options

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

+13
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',
@@ -95,6 +96,18 @@ export default createRule('no-not-function-handler', {
9596
return;
9697
}
9798
verify(node.expression);
99+
},
100+
SvelteAttribute(node) {
101+
if (node.key.type === 'SvelteName' && EVENT_NAMES.includes(node.key.name)) {
102+
const { value } = node;
103+
if (Array.isArray(value)) {
104+
for (const v of value) {
105+
if (v.type === 'SvelteMustacheTag') {
106+
verify(v.expression);
107+
}
108+
}
109+
}
110+
}
98111
}
99112
};
100113
}

0 commit comments

Comments
 (0)