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

Filter by extension

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/pink-walls-fall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix(require-event-prefix) ignore props start with "get"
5 changes: 4 additions & 1 deletion docs/rules/require-event-prefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ since: 'v3.6.0'

Starting with Svelte 5, component events are just component props that are functions and so can be called like any function. Events for HTML elements all have their name begin with "on" (e.g. `onclick`). This rule enforces that all component events (i.e. function props) also begin with "on".

Props that start with "get" are considered getter functions and are automatically excluded from this rule, as they are not events.

<!--eslint-skip-->

```svelte
Expand All @@ -25,9 +27,10 @@ Starting with Svelte 5, component events are just component props that are funct
interface Props {
regularProp: string;
onclick(): void;
getHref(value: any): string;
}

let { regularProp, onclick }: Props = $props();
let { regularProp, onclick, getHref }: Props = $props();
</script>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default createRule('require-event-prefix', {
if (
isFunctionLike(property, tsTools) &&
!property.getName().startsWith('on') &&
!property.getName().startsWith('get') &&
(checkAsyncFunctions || !isFunctionAsync(property, tsTools))
) {
const declarationTsNode = property.getDeclarations()?.[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script lang="ts">
interface Props {
getHref: (value: string) => string;
getLabel: (item: unknown) => string;
}

let { getHref, getLabel }: Props = $props();
</script>