Skip to content

Commit 4112be5

Browse files
authored
Rename vue/no-setup-props-destructure to vue/no-setup-props-reactivity-loss and remove from config (#2268)
1 parent 181e857 commit 4112be5

9 files changed

+1071
-262
lines changed

docs/rules/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ Rules in this category are enabled for all presets provided by eslint-plugin-vue
7979
| [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | | :three::two::hammer: |
8080
| [vue/no-reserved-keys](./no-reserved-keys.md) | disallow overwriting reserved keys | | :three::two::hammer: |
8181
| [vue/no-reserved-props](./no-reserved-props.md) | disallow reserved names in props | | :three::two::warning: |
82-
| [vue/no-setup-props-destructure](./no-setup-props-destructure.md) | disallow destructuring of `props` passed to `setup` | | :three::two::hammer: |
8382
| [vue/no-shared-component-data](./no-shared-component-data.md) | enforce component's data property to be a function | :wrench: | :three::two::warning: |
8483
| [vue/no-side-effects-in-computed-properties](./no-side-effects-in-computed-properties.md) | disallow side effects in computed properties | | :three::two::warning: |
8584
| [vue/no-template-key](./no-template-key.md) | disallow `key` attribute on `<template>` | | :three::two::warning: |
@@ -245,6 +244,7 @@ For example:
245244
| [vue/no-restricted-static-attribute](./no-restricted-static-attribute.md) | disallow specific attribute | | :hammer: |
246245
| [vue/no-restricted-v-bind](./no-restricted-v-bind.md) | disallow specific argument in `v-bind` | | :hammer: |
247246
| [vue/no-root-v-if](./no-root-v-if.md) | disallow `v-if` directives on root element | | :hammer: |
247+
| [vue/no-setup-props-reactivity-loss](./no-setup-props-reactivity-loss.md) | disallow usages that lose the reactivity of `props` passed to `setup` | | :hammer: |
248248
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | | :hammer: |
249249
| [vue/no-template-target-blank](./no-template-target-blank.md) | disallow target="_blank" attribute without rel="noopener noreferrer" | :bulb: | :warning: |
250250
| [vue/no-this-in-before-route-enter](./no-this-in-before-route-enter.md) | disallow `this` usage in a `beforeRouteEnter` method | | :warning: |
@@ -339,6 +339,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
339339
|:--------|:------------|
340340
| [vue/component-tags-order](./component-tags-order.md) | [vue/block-order](./block-order.md) |
341341
| [vue/no-invalid-model-keys](./no-invalid-model-keys.md) | [vue/valid-model-definition](./valid-model-definition.md) |
342+
| [vue/no-setup-props-destructure](./no-setup-props-destructure.md) | [vue/no-setup-props-reactivity-loss](./no-setup-props-reactivity-loss.md) |
342343
| [vue/script-setup-uses-vars](./script-setup-uses-vars.md) | (no replacement) |
343344
| [vue/v-on-function-call](./v-on-function-call.md) | [vue/v-on-handler-style](./v-on-handler-style.md) |
344345

docs/rules/no-setup-props-destructure.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
pageClass: rule-details
33
sidebarDepth: 0
44
title: vue/no-setup-props-destructure
5-
description: disallow destructuring of `props` passed to `setup`
5+
description: disallow usages that lose the reactivity of `props` passed to `setup`
66
since: v7.0.0
77
---
88
# vue/no-setup-props-destructure
99

10-
> disallow destructuring of `props` passed to `setup`
10+
> disallow usages that lose the reactivity of `props` passed to `setup`
1111
12-
- :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"`.
12+
- :no_entry_sign: This rule was **deprecated** and replaced by [vue/no-setup-props-reactivity-loss](no-setup-props-reactivity-loss.md) rule.
1313

1414
## :book: Rule Details
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-setup-props-reactivity-loss
5+
description: disallow usages that lose the reactivity of `props` passed to `setup`
6+
---
7+
# vue/no-setup-props-reactivity-loss
8+
9+
> disallow usages that lose the reactivity of `props` passed to `setup`
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
12+
13+
## :book: Rule Details
14+
15+
This rule reports the destructuring or member expression of `props` passed to `setup` causing the value to lose reactivity.
16+
17+
<eslint-code-block :rules="{'vue/no-setup-props-reactivity-loss': ['error']}">
18+
19+
```vue
20+
<script>
21+
export default {
22+
/* ✓ GOOD */
23+
setup(props) {
24+
watch(() => props.count, () => {
25+
console.log(props.count)
26+
})
27+
28+
return () => {
29+
return h('div', props.count)
30+
}
31+
}
32+
}
33+
</script>
34+
```
35+
36+
</eslint-code-block>
37+
38+
Destructuring the `props` passed to `setup` will cause the value to lose reactivity.
39+
40+
<eslint-code-block :rules="{'vue/no-setup-props-reactivity-loss': ['error']}">
41+
42+
```vue
43+
<script>
44+
export default {
45+
/* ✗ BAD */
46+
setup({ count }) {
47+
watch(() => count, () => { // not going to detect changes
48+
console.log(count)
49+
})
50+
51+
return () => {
52+
return h('div', count) // not going to update
53+
}
54+
}
55+
}
56+
</script>
57+
```
58+
59+
</eslint-code-block>
60+
61+
Also, destructuring in root scope of `setup()` should error, but ok inside nested callbacks or returned render functions:
62+
63+
<eslint-code-block :rules="{'vue/no-setup-props-reactivity-loss': ['error']}">
64+
65+
```vue
66+
<script>
67+
export default {
68+
setup(props) {
69+
/* ✗ BAD */
70+
const { count } = props
71+
72+
watch(() => props.count, () => {
73+
/* ✓ GOOD */
74+
const { count } = props
75+
console.log(count)
76+
})
77+
78+
return () => {
79+
/* ✓ GOOD */
80+
const { count } = props
81+
return h('div', count)
82+
}
83+
}
84+
}
85+
</script>
86+
```
87+
88+
</eslint-code-block>
89+
90+
## :wrench: Options
91+
92+
Nothing.
93+
94+
## :books: Further Reading
95+
96+
- [Guide - Composition API - Setup](https://vuejs.org/api/composition-api-setup.html)
97+
- [Vue RFCs - 0013-composition-api](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0013-composition-api.md)
98+
99+
## :mag: Implementation
100+
101+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-setup-props-reactivity-loss.js)
102+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-setup-props-reactivity-loss.js)

lib/configs/essential.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = {
2828
vueVersion: 2
2929
}
3030
],
31-
'vue/no-setup-props-destructure': 'error',
3231
'vue/no-shared-component-data': 'error',
3332
'vue/no-side-effects-in-computed-properties': 'error',
3433
'vue/no-template-key': 'error',

lib/configs/vue3-essential.js

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = {
4242
'vue/no-reserved-component-names': 'error',
4343
'vue/no-reserved-keys': 'error',
4444
'vue/no-reserved-props': 'error',
45-
'vue/no-setup-props-destructure': 'error',
4645
'vue/no-shared-component-data': 'error',
4746
'vue/no-side-effects-in-computed-properties': 'error',
4847
'vue/no-template-key': 'error',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ module.exports = {
131131
'no-restricted-v-bind': require('./rules/no-restricted-v-bind'),
132132
'no-root-v-if': require('./rules/no-root-v-if'),
133133
'no-setup-props-destructure': require('./rules/no-setup-props-destructure'),
134+
'no-setup-props-reactivity-loss': require('./rules/no-setup-props-reactivity-loss'),
134135
'no-shared-component-data': require('./rules/no-shared-component-data'),
135136
'no-side-effects-in-computed-properties': require('./rules/no-side-effects-in-computed-properties'),
136137
'no-spaces-around-equal-signs-in-attribute': require('./rules/no-spaces-around-equal-signs-in-attribute'),

0 commit comments

Comments
 (0)