@@ -150,6 +150,14 @@ tester.run('no-ref-as-operand', rule, {
150
150
console.log(count + 1) // error
151
151
console.log(1 + count) // error
152
152
` ,
153
+ output : `
154
+ import { ref } from 'vue'
155
+ let count = ref(0)
156
+
157
+ count.value++ // error
158
+ console.log(count.value + 1) // error
159
+ console.log(1 + count.value) // error
160
+ ` ,
153
161
errors : [
154
162
{
155
163
message :
@@ -195,6 +203,23 @@ tester.run('no-ref-as-operand', rule, {
195
203
}
196
204
</script>
197
205
` ,
206
+ output : `
207
+ <script>
208
+ import { ref } from 'vue'
209
+ export default {
210
+ setup() {
211
+ let count = ref(0)
212
+
213
+ count.value++ // error
214
+ console.log(count.value + 1) // error
215
+ console.log(1 + count.value) // error
216
+ return {
217
+ count
218
+ }
219
+ }
220
+ }
221
+ </script>
222
+ ` ,
198
223
errors : [
199
224
{
200
225
messageId : 'requireDotValue' ,
@@ -237,6 +262,23 @@ tester.run('no-ref-as-operand', rule, {
237
262
}
238
263
</script>
239
264
` ,
265
+ output : `
266
+ <script>
267
+ import { ref } from '@vue/composition-api'
268
+ export default {
269
+ setup() {
270
+ let count = ref(0)
271
+
272
+ count.value++ // error
273
+ console.log(count.value + 1) // error
274
+ console.log(1 + count.value) // error
275
+ return {
276
+ count
277
+ }
278
+ }
279
+ }
280
+ </script>
281
+ ` ,
240
282
errors : [
241
283
{
242
284
messageId : 'requireDotValue' ,
@@ -269,6 +311,13 @@ tester.run('no-ref-as-operand', rule, {
269
311
//
270
312
}
271
313
` ,
314
+ output : `
315
+ import { ref } from 'vue'
316
+ const foo = ref(true)
317
+ if (foo.value) {
318
+ //
319
+ }
320
+ ` ,
272
321
errors : [
273
322
{
274
323
messageId : 'requireDotValue' ,
@@ -284,6 +333,13 @@ tester.run('no-ref-as-operand', rule, {
284
333
//
285
334
}
286
335
` ,
336
+ output : `
337
+ import { ref } from 'vue'
338
+ const foo = ref(true)
339
+ switch (foo.value) {
340
+ //
341
+ }
342
+ ` ,
287
343
errors : [
288
344
{
289
345
messageId : 'requireDotValue' ,
@@ -300,6 +356,14 @@ tester.run('no-ref-as-operand', rule, {
300
356
var c = !foo
301
357
var d = ~foo
302
358
` ,
359
+ output : `
360
+ import { ref } from 'vue'
361
+ const foo = ref(0)
362
+ var a = -foo.value
363
+ var b = +foo.value
364
+ var c = !foo.value
365
+ var d = ~foo.value
366
+ ` ,
303
367
errors : [
304
368
{
305
369
messageId : 'requireDotValue' ,
@@ -328,6 +392,14 @@ tester.run('no-ref-as-operand', rule, {
328
392
baz += foo
329
393
baz -= foo
330
394
` ,
395
+ output : `
396
+ import { ref } from 'vue'
397
+ let foo = ref(0)
398
+ foo.value += 1
399
+ foo.value -= 1
400
+ baz += foo.value
401
+ baz -= foo.value
402
+ ` ,
331
403
errors : [
332
404
{
333
405
messageId : 'requireDotValue' ,
@@ -354,6 +426,12 @@ tester.run('no-ref-as-operand', rule, {
354
426
var a = foo || other
355
427
var b = foo && other
356
428
` ,
429
+ output : `
430
+ import { ref } from 'vue'
431
+ const foo = ref(true)
432
+ var a = foo.value || other
433
+ var b = foo.value && other
434
+ ` ,
357
435
errors : [
358
436
{
359
437
messageId : 'requireDotValue' ,
@@ -371,6 +449,11 @@ tester.run('no-ref-as-operand', rule, {
371
449
let foo = ref(true)
372
450
var a = foo ? x : y
373
451
` ,
452
+ output : `
453
+ import { ref } from 'vue'
454
+ let foo = ref(true)
455
+ var a = foo.value ? x : y
456
+ ` ,
374
457
errors : [
375
458
{
376
459
messageId : 'requireDotValue' ,
@@ -395,6 +478,22 @@ tester.run('no-ref-as-operand', rule, {
395
478
}
396
479
</script>
397
480
` ,
481
+ output : `
482
+ <script>
483
+ import { ref } from 'vue'
484
+ let count = ref(0)
485
+ export default {
486
+ setup() {
487
+ count.value++ // error
488
+ console.log(count.value + 1) // error
489
+ console.log(1 + count.value) // error
490
+ return {
491
+ count
492
+ }
493
+ }
494
+ }
495
+ </script>
496
+ ` ,
398
497
errors : [
399
498
{
400
499
messageId : 'requireDotValue' ,
@@ -451,6 +550,46 @@ tester.run('no-ref-as-operand', rule, {
451
550
const n = foo + 1 // error
452
551
</script>
453
552
` ,
553
+ output : `
554
+ <script>
555
+ import { ref, computed, toRef, customRef, shallowRef } from 'vue'
556
+ let count = ref(0)
557
+ let cntcnt = computed(()=>count.value+count.value)
558
+
559
+ const state = reactive({
560
+ foo: 1,
561
+ bar: 2
562
+ })
563
+
564
+ const fooRef = toRef(state, 'foo')
565
+
566
+ let value = 'hello'
567
+ const cref = customRef((track, trigger) => {
568
+ return {
569
+ get() {
570
+ track()
571
+ return value
572
+ },
573
+ set(newValue) {
574
+ clearTimeout(timeout)
575
+ timeout = setTimeout(() => {
576
+ value = newValue
577
+ trigger()
578
+ }, delay)
579
+ }
580
+ }
581
+ })
582
+
583
+ const foo = shallowRef({})
584
+
585
+ count.value++ // error
586
+ cntcnt.value++ // error
587
+
588
+ const s = \`\${fooRef.value} : \${cref.value}\` // error x 2
589
+
590
+ const n = foo.value + 1 // error
591
+ </script>
592
+ ` ,
454
593
errors : [
455
594
{
456
595
message :
@@ -487,6 +626,13 @@ tester.run('no-ref-as-operand', rule, {
487
626
foo.bar = 123
488
627
</script>
489
628
` ,
629
+ output : `
630
+ <script>
631
+ import { ref, computed, toRef, customRef, shallowRef } from 'vue'
632
+ const foo = shallowRef({})
633
+ foo.value.bar = 123
634
+ </script>
635
+ ` ,
490
636
errors : [
491
637
{
492
638
messageId : 'requireDotValue'
@@ -501,6 +647,13 @@ tester.run('no-ref-as-operand', rule, {
501
647
const bar = foo?.bar
502
648
</script>
503
649
` ,
650
+ output : `
651
+ <script>
652
+ import { ref } from 'vue'
653
+ const foo = ref(123)
654
+ const bar = foo.value?.bar
655
+ </script>
656
+ ` ,
504
657
errors : [
505
658
{
506
659
messageId : 'requireDotValue'
0 commit comments