vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.39k stars 652 forks source link

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

Open cjpearson opened 2 months ago

cjpearson commented 2 months ago

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.