Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Request: writable.update() should always return a value #682

Open
tivac opened this issue Feb 12, 2024 · 1 comment
Open

Rule Request: writable.update() should always return a value #682

tivac opened this issue Feb 12, 2024 · 1 comment
Labels
enhancement New feature or request new rule

Comments

@tivac
Copy link
Collaborator

tivac commented Feb 12, 2024

Motivation

If you use the .update(...) method on a writable store and don't explicitly return a value the store will be set to undefined. That might be on purpose, but I'm willing to bet that more often than not it's accidental.

Description

The rule should look for .update() calls that match the signature of writable.update() and ensure that all code paths return some value. Doesn't have to the be the original value or anything specific, I just think being able to require the usage of return <thing>; to make it really explicit that a value is being set would be useful and prevent errors.

Examples

<script>
const store = writable(false);

// ✓ GOOD
store.update(($store) => true);

store.update(($store) => {
    return true;
});

store.update(($store) => {
    if(foo) {
        // ...
        return bar;
    }

    return true;
});

// ✗ BAD
store.update(($store) => {
    // ...
});

store.update(($store) => {
    if(foo) {
        // ...
        return bar;
    }
});
</script>

Additional comments

No response

@tivac tivac added enhancement New feature or request new rule labels Feb 12, 2024
@ota-meshi
Copy link
Member

Thank you for posting rule suggestion!
That rule sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

No branches or pull requests

2 participants