Skip to content

Commit 6bea92e

Browse files
committed
Add check for watchEffect.
1 parent 21f7e0d commit 6bea92e

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

docs/rules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
5858
| [vue/no-unused-components](./no-unused-components.md) | disallow registering components that are not used inside templates | |
5959
| [vue/no-unused-vars](./no-unused-vars.md) | disallow unused variable definitions of v-for directives or scope attributes | |
6060
| [vue/no-use-v-if-with-v-for](./no-use-v-if-with-v-for.md) | disallow use v-if on the same element as v-for | |
61+
| [vue/no-watch-after-await](./no-watch-after-await.md) | disallow asynchronously registered `watch` | |
6162
| [vue/require-component-is](./require-component-is.md) | require `v-bind:is` of `<component>` elements | |
6263
| [vue/require-prop-type-constructor](./require-prop-type-constructor.md) | require prop type to be a constructor | :wrench: |
6364
| [vue/require-render-return](./require-render-return.md) | enforce render function to always return value | |
@@ -273,7 +274,6 @@ For example:
273274
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
274275
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |
275276
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
276-
| [vue/no-watch-after-await](./no-watch-after-await.md) | disallow asynchronously registered `watch` | |
277277
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
278278
| [vue/padding-line-between-blocks](./padding-line-between-blocks.md) | require or disallow padding lines between blocks | :wrench: |
279279
| [vue/require-direct-export](./require-direct-export.md) | require the component to be directly exported | |

docs/rules/no-watch-after-await.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ description: disallow asynchronously registered `watch`
77
# vue/no-watch-after-await
88
> disallow asynchronously registered `watch`
99
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`.
11+
1012
## :book: Rule Details
1113

1214
This rule reports the `watch()` after `await` expression.

lib/configs/vue3-essential.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = {
2626
'vue/no-unused-components': 'error',
2727
'vue/no-unused-vars': 'error',
2828
'vue/no-use-v-if-with-v-for': 'error',
29+
'vue/no-watch-after-await': 'error',
2930
'vue/require-component-is': 'error',
3031
'vue/require-prop-type-constructor': 'error',
3132
'vue/require-render-return': 'error',

lib/rules/no-watch-after-await.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
type: 'suggestion',
1212
docs: {
1313
description: 'disallow asynchronously registered `watch`',
14-
category: undefined,
14+
categories: ['vue3-essential'],
1515
url: 'https://eslint.vuejs.org/rules/no-watch-after-await.html'
1616
},
1717
fixable: null,
@@ -45,6 +45,9 @@ module.exports = {
4545
[ReferenceTracker.ESM]: true,
4646
watch: {
4747
[ReferenceTracker.CALL]: true
48+
},
49+
watchEffect: {
50+
[ReferenceTracker.CALL]: true
4851
}
4952
}
5053
}

tests/lib/rules/no-watch-after-await.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ tester.run('no-watch-after-await', rule, {
4141
</script>
4242
`
4343
},
44+
{
45+
filename: 'test.vue',
46+
code: `
47+
<script>
48+
import {watch, watchEffect} from 'vue'
49+
export default {
50+
async setup() {
51+
watchEffect(() => { /* ... */ })
52+
watch(() => { /* ... */ })
53+
await doSomething()
54+
}
55+
}
56+
</script>
57+
`
58+
},
4459
{
4560
filename: 'test.vue',
4661
code: `
@@ -82,6 +97,32 @@ tester.run('no-watch-after-await', rule, {
8297
}
8398
]
8499
},
100+
{
101+
filename: 'test.vue',
102+
code: `
103+
<script>
104+
import {watch, watchEffect} from 'vue'
105+
export default {
106+
async setup() {
107+
await doSomething()
108+
109+
watchEffect(() => { /* ... */ })
110+
watch(() => { /* ... */ })
111+
}
112+
}
113+
</script>
114+
`,
115+
errors: [
116+
{
117+
messageId: 'forbidden',
118+
line: 8
119+
},
120+
{
121+
messageId: 'forbidden',
122+
line: 9
123+
}
124+
]
125+
},
85126
{
86127
filename: 'test.vue',
87128
code: `

0 commit comments

Comments
 (0)