diff --git a/docs/rules/README.md b/docs/rules/README.md index 4327caf50..8916464e6 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -38,6 +38,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi | Rule ID | Description | | |:--------|:------------|:---| +| [vue/no-arrow-functions-in-watch](./no-arrow-functions-in-watch.md) | disallow using arrow functions to define watcher | | | [vue/no-async-in-computed-properties](./no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties | | | [vue/no-deprecated-data-object-declaration](./no-deprecated-data-object-declaration.md) | disallow using deprecated object declaration on data (in Vue.js 3.0.0+) | :wrench: | | [vue/no-deprecated-dollar-listeners-api](./no-deprecated-dollar-listeners-api.md) | disallow using deprecated `$listeners` (in Vue.js 3.0.0+) | | @@ -159,6 +160,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi | Rule ID | Description | | |:--------|:------------|:---| +| [vue/no-arrow-functions-in-watch](./no-arrow-functions-in-watch.md) | disallow using arrow functions to define watcher | | | [vue/no-async-in-computed-properties](./no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties | | | [vue/no-custom-modifiers-on-v-model](./no-custom-modifiers-on-v-model.md) | disallow custom modifiers on v-model used on the component | | | [vue/no-dupe-keys](./no-dupe-keys.md) | disallow duplication of field names | | @@ -286,7 +288,6 @@ For example: | [vue/keyword-spacing](./keyword-spacing.md) | enforce consistent spacing before and after keywords | :wrench: | | [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | | | [vue/max-len](./max-len.md) | enforce a maximum line length | | -| [vue/no-arrow-functions-in-watch](./no-arrow-functions-in-watch.md)| disallows using arrow functions to define wathcer | | | [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: | | [vue/no-duplicate-attr-inheritance](./no-duplicate-attr-inheritance.md) | enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` | | | [vue/no-empty-pattern](./no-empty-pattern.md) | disallow empty destructuring patterns | | diff --git a/docs/rules/no-arrow-functions-in-watch.md b/docs/rules/no-arrow-functions-in-watch.md index 7da767330..4378fe567 100644 --- a/docs/rules/no-arrow-functions-in-watch.md +++ b/docs/rules/no-arrow-functions-in-watch.md @@ -2,11 +2,13 @@ pageClass: rule-details sidebarDepth: 0 title: vue/no-arrow-functions-in-watch -description: disallow arrow functions to define watcher +description: disallow using arrow functions to define watcher --- # vue/no-arrow-functions-in-watch > disallow using arrow functions to define watcher +- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/essential"`, `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`. + ## :book: Rule Details This rules disallows using arrow functions to defined watcher.The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect.([see here for more details](https://vuejs.org/v2/api/#watch)) diff --git a/lib/configs/essential.js b/lib/configs/essential.js index f85195de1..92a9e7405 100644 --- a/lib/configs/essential.js +++ b/lib/configs/essential.js @@ -6,6 +6,7 @@ module.exports = { extends: require.resolve('./base'), rules: { + 'vue/no-arrow-functions-in-watch': 'error', 'vue/no-async-in-computed-properties': 'error', 'vue/no-custom-modifiers-on-v-model': 'error', 'vue/no-dupe-keys': 'error', diff --git a/lib/configs/vue3-essential.js b/lib/configs/vue3-essential.js index c8e630496..9ae00e5e1 100644 --- a/lib/configs/vue3-essential.js +++ b/lib/configs/vue3-essential.js @@ -6,6 +6,7 @@ module.exports = { extends: require.resolve('./base'), rules: { + 'vue/no-arrow-functions-in-watch': 'error', 'vue/no-async-in-computed-properties': 'error', 'vue/no-deprecated-data-object-declaration': 'error', 'vue/no-deprecated-dollar-listeners-api': 'error', diff --git a/lib/rules/no-arrow-functions-in-watch.js b/lib/rules/no-arrow-functions-in-watch.js index ab8a608da..4df3ec27d 100644 --- a/lib/rules/no-arrow-functions-in-watch.js +++ b/lib/rules/no-arrow-functions-in-watch.js @@ -10,7 +10,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow using arrow functions to define watcher', - categories: undefined, + categories: ['vue3-essential', 'essential'], url: 'https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html' }, fixable: null,