From 6bea92efebcd54b4fa60c980c07978cb868bf2f1 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 7 Mar 2020 18:10:13 +0900 Subject: [PATCH] Add check for watchEffect. --- docs/rules/README.md | 2 +- docs/rules/no-watch-after-await.md | 2 ++ lib/configs/vue3-essential.js | 1 + lib/rules/no-watch-after-await.js | 5 ++- tests/lib/rules/no-watch-after-await.js | 41 +++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/docs/rules/README.md b/docs/rules/README.md index 233b1d136..90f024965 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -58,6 +58,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi | [vue/no-unused-components](./no-unused-components.md) | disallow registering components that are not used inside templates | | | [vue/no-unused-vars](./no-unused-vars.md) | disallow unused variable definitions of v-for directives or scope attributes | | | [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 | | +| [vue/no-watch-after-await](./no-watch-after-await.md) | disallow asynchronously registered `watch` | | | [vue/require-component-is](./require-component-is.md) | require `v-bind:is` of `` elements | | | [vue/require-prop-type-constructor](./require-prop-type-constructor.md) | require prop type to be a constructor | :wrench: | | [vue/require-render-return](./require-render-return.md) | enforce render function to always return value | | @@ -273,7 +274,6 @@ For example: | [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | | | [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | | | [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: | -| [vue/no-watch-after-await](./no-watch-after-await.md) | disallow asynchronously registered `watch` | | | [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: | | [vue/padding-line-between-blocks](./padding-line-between-blocks.md) | require or disallow padding lines between blocks | :wrench: | | [vue/require-direct-export](./require-direct-export.md) | require the component to be directly exported | | diff --git a/docs/rules/no-watch-after-await.md b/docs/rules/no-watch-after-await.md index a0b2d9b61..999c2afc9 100644 --- a/docs/rules/no-watch-after-await.md +++ b/docs/rules/no-watch-after-await.md @@ -7,6 +7,8 @@ description: disallow asynchronously registered `watch` # vue/no-watch-after-await > disallow asynchronously registered `watch` +- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`. + ## :book: Rule Details This rule reports the `watch()` after `await` expression. diff --git a/lib/configs/vue3-essential.js b/lib/configs/vue3-essential.js index 3e45ddd2c..6a41aebbc 100644 --- a/lib/configs/vue3-essential.js +++ b/lib/configs/vue3-essential.js @@ -26,6 +26,7 @@ module.exports = { 'vue/no-unused-components': 'error', 'vue/no-unused-vars': 'error', 'vue/no-use-v-if-with-v-for': 'error', + 'vue/no-watch-after-await': 'error', 'vue/require-component-is': 'error', 'vue/require-prop-type-constructor': 'error', 'vue/require-render-return': 'error', diff --git a/lib/rules/no-watch-after-await.js b/lib/rules/no-watch-after-await.js index 11d33ec3a..7ffd04099 100644 --- a/lib/rules/no-watch-after-await.js +++ b/lib/rules/no-watch-after-await.js @@ -11,7 +11,7 @@ module.exports = { type: 'suggestion', docs: { description: 'disallow asynchronously registered `watch`', - category: undefined, + categories: ['vue3-essential'], url: 'https://eslint.vuejs.org/rules/no-watch-after-await.html' }, fixable: null, @@ -45,6 +45,9 @@ module.exports = { [ReferenceTracker.ESM]: true, watch: { [ReferenceTracker.CALL]: true + }, + watchEffect: { + [ReferenceTracker.CALL]: true } } } diff --git a/tests/lib/rules/no-watch-after-await.js b/tests/lib/rules/no-watch-after-await.js index 5baa0f1af..1adc15aab 100644 --- a/tests/lib/rules/no-watch-after-await.js +++ b/tests/lib/rules/no-watch-after-await.js @@ -41,6 +41,21 @@ tester.run('no-watch-after-await', rule, { ` }, + { + filename: 'test.vue', + code: ` + + ` + }, { filename: 'test.vue', code: ` @@ -82,6 +97,32 @@ tester.run('no-watch-after-await', rule, { } ] }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + messageId: 'forbidden', + line: 8 + }, + { + messageId: 'forbidden', + line: 9 + } + ] + }, { filename: 'test.vue', code: `