Skip to content

Commit 563fc56

Browse files
committed
fix(require-event-prefix): ignore getters
1 parent 6e68978 commit 563fc56

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/rules/require-event-prefix.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ since: 'v3.6.0'
1414

1515
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".
1616

17+
Props that start with "get" are considered getter functions and are automatically excluded from this rule, as they are not events.
18+
1719
<!--eslint-skip-->
1820

1921
```svelte
@@ -25,9 +27,10 @@ Starting with Svelte 5, component events are just component props that are funct
2527
interface Props {
2628
regularProp: string;
2729
onclick(): void;
30+
getHref(value: any): string;
2831
}
2932
30-
let { regularProp, onclick }: Props = $props();
33+
let { regularProp, onclick, getHref }: Props = $props();
3134
</script>
3235
```
3336

packages/eslint-plugin-svelte/src/rules/require-event-prefix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default createRule('require-event-prefix', {
6060
if (
6161
isFunctionLike(property, tsTools) &&
6262
!property.getName().startsWith('on') &&
63+
!property.getName().startsWith('get') &&
6364
(checkAsyncFunctions || !isFunctionAsync(property, tsTools))
6465
) {
6566
const declarationTsNode = property.getDeclarations()?.[0];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script lang="ts">
2+
interface Props {
3+
getHref: (value: string) => string;
4+
getLabel: (item: unknown) => string;
5+
}
6+
7+
let { getHref, getLabel }: Props = $props();
8+
</script>

0 commit comments

Comments
 (0)