Skip to content

Commit

Permalink
docs(require-event-prefix): added rule docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Feb 10, 2025
1 parent ad6451b commit 3ff1ae5
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/rules/require-event-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
pageClass: 'rule-details'
sidebarDepth: 0
title: 'svelte/require-event-prefix'
description: 'require component event names to start with "on"'
---

# svelte/require-event-prefix

> require component event names to start with "on"
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>

## :book: Rule Details

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

<!--eslint-skip-->

```svelte
<script lang="ts">
/* eslint svelte/require-event-prefix: "error" */
/* ✓ GOOD */
interface Props {
regularProp: string;
onclick(): void;
}
let { regularProp, onclick }: Props = $props();
</script>
```

```svelte
<script lang="ts">
/* eslint svelte/require-event-prefix: "error" */
/* ✗ BAD */
interface Props {
click(): void;
}
let { click }: Props = $props();
</script>
```

## :wrench: Options

```json
{
"svelte/require-event-prefix": [
"error",
{
"checkAsyncFunctions": false
}
]
}
```

- `checkAsyncFunctions` ... Whether to also report asychronous function properties. Default `false`.

## :books: Further Reading

- [Svelte docs on events in version 5](https://svelte.dev/docs/svelte/v5-migration-guide#Event-changes)

## :mag: Implementation

- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/require-event-prefix.ts)
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/require-event-prefix.ts)

0 comments on commit 3ff1ae5

Please sign in to comment.