Description
Please describe what the rule should do:
This rule enforces that you can't directly call a composable inside an event handler.
Calling a composable inside an event handler directly can cause issues. For example when we call
onMounted
inside that composable, we'll get an error because onMounted
is called outside the Vue context.
Here's an example
What category should the rule belong to?
[ ] Enforces code style (layout)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
<template>
<button @click="useFoo">Click me!</button>
</template>
<script setup>
function useFoo() {
onMounted() {}
fetch('/api);
}
</script>
Additional context
To determine wether something is a composable, we check if a function starts with use
. This is the standard convention for Vue.
Note: I would help to create a PR for that rule