# svelte/require-event-prefix

require component event names to start with β€œon”

  • ❗ This rule has not been released yet.

# πŸ“– 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”.

<script lang="ts">
  /* eslint svelte/require-event-prefix: "error" */

  /* βœ“ GOOD */

  interface Props {
    regularProp: string;
    onclick(): void;
  }

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

  /* βœ— BAD */

  interface Props {
    click(): void;
  }

  let { click }: Props = $props();
</script>

# πŸ”§ Options

{
  "svelte/require-event-prefix": [
    "error",
    {
      "checkAsyncFunctions": false
    }
  ]
}
  • checkAsyncFunctions … Whether to also report asychronous function properties. Default false.

# πŸ“š Further Reading

# πŸ” Implementation