-
-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
Description
Motivation
AI Coding agents sometimes get a bit confused writing Svelte 5 and create code like this:
let x = $derived(() => values.filter((item) => item.active));
This, of course, makes x
into a function instead of the value, and the coding agents often work around this by just changing the uses of x
to x()
, instead of fixing it properly to use derived.by or a single-expresssion $derived.
It would be helpful to have a lint rule for this.
Description
A $derived rune should not return a function. Either use a single expression with $derived or use $derived.by with a function.
Examples
<script>
// ✓ GOOD
let x = $derived(expression);
let x = $derived.by(() => expression);
let x = $derived.by(() => {
return complexExpression;
});
let x = $derived(calculate(value));
let x = $derived.by(calculate);
// ✗ BAD
let x =$derived(() => y);
let x =$derived(function() { return y });
</script>
Additional comments
No response