Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-dots-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': minor
---

feat: add Svelte 5 support to `no-not-function-handler`
8 changes: 4 additions & 4 deletions docs/rules/no-not-function-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ If you use a non-function value for the event handler, it event handler will not
</script>

<!-- ✓ GOOD -->
<button on:click={foo} />
<button onclick={foo} />
<button
on:click={() => {
onclick={() => {
/* */
}}
/>

<!-- ✗ BAD -->
<button on:click={{ foo }} />
<button on:click={bar} />
<button onclick={{ foo }} />
<button onclick={bar} />
```

## :wrench: Options
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-plugin-svelte/src/rules/no-not-function-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AST } from 'svelte-eslint-parser';
import type { TSESTree } from '@typescript-eslint/types';
import { createRule } from '../utils/index.js';
import { findVariable } from '../utils/ast-utils.js';
import { EVENT_NAMES } from '../utils/events.js';

const PHRASES = {
ObjectExpression: 'object',
Expand Down Expand Up @@ -95,6 +96,18 @@ export default createRule('no-not-function-handler', {
return;
}
verify(node.expression);
},
SvelteAttribute(node) {
if (node.key.type === 'SvelteName' && EVENT_NAMES.includes(node.key.name)) {
const { value } = node;
if (Array.isArray(value)) {
for (const v of value) {
if (v.type === 'SvelteMustacheTag') {
verify(v.expression);
}
}
}
}
}
};
}
Expand Down
Loading
Loading