-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(require-event-prefix): added rule docs
- Loading branch information
1 parent
ad6451b
commit 3ff1ae5
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |