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 proposal: no-computed-after-await #2451

Open
cjpearson opened this issue Apr 15, 2024 · 1 comment
Open

Rule proposal: no-computed-after-await #2451

cjpearson opened this issue Apr 15, 2024 · 1 comment

Comments

@cjpearson
Copy link
Contributor

Please describe what the rule should do:

Disallow asynchronously registered watch

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:)

<script>
import { computed } from 'vue'
export default {
  async setup() {
    /* ✓ GOOD */
    computed(() => { /* ... */ })

    await doSomething()

    /* ✗ BAD */
    computed(() => { /* ... */ })
  }
}
</script>

Additional context

This rule is based on no-watch-after-await. According to the documentation, watch and computed must be called synchronously in order for them to be properly cleaned up. There is currently the no-watch-after-await rule to catch asynchronous calls of watch, but no comparable rule for computed.

@waynzh
Copy link
Contributor

waynzh commented Apr 30, 2024

Before this rule gets adopted, you could use no-restricted-call-after-await as a temporary workaround:

"vue/no-restricted-call-after-await": ["error",
    { "module": "vue", "path": "computed" },
  ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants