@@ -56,6 +56,44 @@ This rule disallows to use computed property like method.
56
56
},
57
57
},
58
58
computed: {
59
+ computedReturnDataString() {
60
+ return this.dataString
61
+ },
62
+ computedReturnDataNumber() {
63
+ return this.dataNumber
64
+ },
65
+ computedReturnDataObject() {
66
+ return this.dataObject
67
+ },
68
+ computedReturnDataArray() {
69
+ return this.dataArray
70
+ },
71
+ computedReturnDataBoolean() {
72
+ return this.dataBoolean
73
+ },
74
+ computedReturnDataFunction() {
75
+ return this.dataFunction
76
+ },
77
+
78
+ computedReturnPropsString() {
79
+ return this.propsString
80
+ },
81
+ computedReturnPropsNumber() {
82
+ return this.propsNumber
83
+ },
84
+ computedReturnPropsObject() {
85
+ return this.propsObject
86
+ },
87
+ computedReturnPropsArray() {
88
+ return this.propsArray
89
+ },
90
+ computedReturnPropsBoolean() {
91
+ return this.propsBoolean
92
+ },
93
+ computedReturnPropsFunction() {
94
+ return this.propsFunction
95
+ },
96
+
59
97
computedReturnString() {
60
98
return 'computedReturnString'
61
99
},
@@ -76,7 +114,24 @@ This rule disallows to use computed property like method.
76
114
computedReturnFunction() {
77
115
const fn = () => alert('computedReturnFunction')
78
116
return fn
117
+ },
118
+
119
+ computedReturnMethodsReturnString() {
120
+ return this.methodsReturnString
121
+ },
122
+ computedReturnMethodsReturnNumber() {
123
+ return this.methodsReturnNumber
124
+ },
125
+ computedReturnMethodsReturnObject() {
126
+ return this.methodsReturnObject
127
+ },
128
+ computedReturnMethodsReturnArray() {
129
+ return this.methodsReturnArray
130
+ },
131
+ computedReturnMethodsReturnBoolean() {
132
+ return this.methodsReturnBoolean
79
133
}
134
+
80
135
},
81
136
methods: {
82
137
methodsReturnString() {
@@ -97,7 +152,137 @@ This rule disallows to use computed property like method.
97
152
return true
98
153
},
99
154
methodsReturnFunction() {
100
- console.log(this.dataObject.inside);
155
+ const fn = () => alert('methodsReturnFunction')
156
+ return fn
157
+ },
158
+
159
+ fn() {
160
+ /* Reference data */
161
+ /* ✓ GOOD */
162
+ this.computedReturnDataString
163
+ this.computedReturnDataNumber
164
+ this.computedReturnDataObject
165
+ this.computedReturnDataArray
166
+ this.computedReturnDataBoolean
167
+ this.computedReturnDataFunction
168
+ this.computedReturnDataFunction()
169
+ /* ✗ BAD */
170
+ this.computedReturnDataString()
171
+ this.computedReturnDataNumber()
172
+ this.computedReturnDataObject()
173
+ this.computedReturnDataArray()
174
+ this.computedReturnDataBoolean()
175
+
176
+ /* Reference props */
177
+ /* ✓ GOOD */
178
+ this.computedReturnPropsString
179
+ this.computedReturnPropsNumber
180
+ this.computedReturnPropsObject
181
+ this.computedReturnPropsArray
182
+ this.computedReturnPropsBoolean
183
+ this.computedReturnPropsFunction
184
+ this.computedReturnPropsFunction()
185
+ /* ✗ BAD */
186
+ this.computedReturnPropsString()
187
+ this.computedReturnPropsNumber()
188
+ this.computedReturnPropsObject()
189
+ this.computedReturnPropsArray()
190
+ this.computedReturnPropsBoolean()
191
+
192
+ /* ✓ GOOD */
193
+ this.computedReturnString
194
+ this.computedReturnNumber
195
+ this.computedReturnObject
196
+ this.computedReturnArray
197
+ this.computedReturnBoolean
198
+ this.computedReturnFunction
199
+ this.computedReturnFunction()
200
+ /* ✗ BAD */
201
+ this.computedReturnString()
202
+ this.computedReturnNumber()
203
+ this.computedReturnObject()
204
+ this.computedReturnArray()
205
+ this.computedReturnBoolean()
206
+
207
+ /* Reference methods */
208
+ /* ✓ GOOD */
209
+ this.computedReturnMethodsReturnString
210
+ this.computedReturnMethodsReturnNumber
211
+ this.computedReturnMethodsReturnObject
212
+ this.computedReturnMethodsReturnArray
213
+ this.computedReturnMethodsReturnBoolean
214
+ this.computedReturnMethodsReturnFunction
215
+ this.computedReturnMethodsReturnFunction()
216
+ /* ✗ BAD */
217
+ this.computedReturnMethodsReturnString()
218
+ this.computedReturnMethodsReturnNumber()
219
+ this.computedReturnMethodsReturnObject()
220
+ this.computedReturnMethodsReturnArray()
221
+ this.computedReturnMethodsReturnBoolean()
222
+ }
223
+ }
224
+ }
225
+ </script>
226
+ ```
227
+
228
+ This rule can't check if props is used as array:
229
+ </eslint-code-block >
230
+ <eslint-code-block :rules =" {'vue/no-use-computed-property-like-method': ['error']} " >
231
+
232
+ ``` vue
233
+ <template>
234
+ <div>
235
+ </div>
236
+ </template>
237
+
238
+ <script>
239
+ export default {
240
+ props: {
241
+ "propsString",
242
+ "propsNumber",
243
+ "propsObject",
244
+ "propsArray",
245
+ "propsBoolean",
246
+ "propsFunction"
247
+ },
248
+ computed: {
249
+ computedReturnPropsString() {
250
+ return this.propsString
251
+ },
252
+ computedReturnPropsNumber() {
253
+ return this.propsNumber
254
+ },
255
+ computedReturnPropsObject() {
256
+ return this.propsObject
257
+ },
258
+ computedReturnPropsArray() {
259
+ return this.propsArray
260
+ },
261
+ computedReturnPropsBoolean() {
262
+ return this.propsBoolean
263
+ },
264
+ computedReturnPropsFunction() {
265
+ return this.propsFunction
266
+ },
267
+ },
268
+ methods: {
269
+ fn() {
270
+ /* Reference props */
271
+ /* ✓ GOOD */
272
+ this.computedReturnPropsString
273
+ this.computedReturnPropsString()
274
+ this.computedReturnPropsNumber
275
+ this.computedReturnPropsNumber()
276
+ this.computedReturnPropsObject
277
+ this.computedReturnPropsObject()
278
+ this.computedReturnPropsArray
279
+ this.computedReturnPropsArray()
280
+ this.computedReturnPropsBoolean
281
+ this.computedReturnPropsBoolean()
282
+ this.computedReturnPropsFunction
283
+ this.computedReturnPropsFunction()
284
+ /* ✗ BAD */
285
+ /* Nope. everything is GOOD!! */
101
286
}
102
287
}
103
288
}
0 commit comments