Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.01 KB

no-initialized-rune-return.md

File metadata and controls

44 lines (32 loc) · 1.01 KB

Rule Name: no-initialized-rune-returns

Disallow directly returning values initialized with $state or $derived Svelte runes from functions.

📜 Rule Details

Directly returning values initialized with Svelte's $state or $derived from functions will not preserve their reactivity, leading to unexpected behavior. To maintain reactivity when returning these values, use getters and setters in an object.

Examples of incorrect code for this rule:

function getCount() {
    const count = $state(0);
    return count; 
}

Examples of correct code for this rule:

function getCount() {
    let count = $state(0);
    return {
        get value() {
            return count;
        },
        set value(newValue) {
            count = newValue;
        }
    };
}

⚙️ Options

This rule does not have any optional settings. Use it as:

"svelte-runes/no-initialized-rune-returns": ["error"]

🤖 Version

Introduced in eslint-plugin-svelte-runes v0.0.11.