|
| 1 | +import { stripIndent } from 'common-tags'; |
| 2 | +import { noSharereplayBeforeTakeuntilRule } from '../../src/rules/no-sharereplay-before-takeuntil'; |
| 3 | +import { fromFixture } from '../etc'; |
| 4 | +import { ruleTester } from '../rule-tester'; |
| 5 | + |
| 6 | +ruleTester({ types: false }).run('no-sharereplay-before-takeuntil', noSharereplayBeforeTakeuntilRule, { |
| 7 | + valid: [ |
| 8 | + stripIndent` |
| 9 | + // with refCount true |
| 10 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 11 | +
|
| 12 | + const a = of("a"); |
| 13 | + const b = of("b"); |
| 14 | +
|
| 15 | + a.pipe(shareReplay({ refCount: true }), takeUntil(b)); |
| 16 | + `, |
| 17 | + stripIndent` |
| 18 | + // with refCount true as const |
| 19 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 20 | +
|
| 21 | + const a = of("a"); |
| 22 | + const b = of("b"); |
| 23 | +
|
| 24 | + const t = true as const; |
| 25 | + a.pipe(shareReplay({ refCount: t }), takeUntil(b)); |
| 26 | + `, |
| 27 | + stripIndent` |
| 28 | + // refCount as variable not supported |
| 29 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 30 | +
|
| 31 | + const a = of("a"); |
| 32 | + const b = of("b"); |
| 33 | +
|
| 34 | + const t = false; |
| 35 | + a.pipe(shareReplay({ refCount: t }), takeUntil(b)); |
| 36 | + `, |
| 37 | + stripIndent` |
| 38 | + // composed observables not supported |
| 39 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 40 | +
|
| 41 | + const a = of("a"); |
| 42 | + const b = of("b"); |
| 43 | +
|
| 44 | + const sr = shareReplay({ refCount: false }); |
| 45 | + a.pipe(sr, takeUntil(b)); |
| 46 | + `, |
| 47 | + stripIndent` |
| 48 | + // shareReplay after takeUntil |
| 49 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 50 | +
|
| 51 | + const a = of("a"); |
| 52 | + const b = of("b"); |
| 53 | +
|
| 54 | + a.pipe(takeUntil(b), shareReplay({ refCount: false })); |
| 55 | + `, |
| 56 | + stripIndent` |
| 57 | + // shareReplay after takeUntil with operators in between |
| 58 | + import { of, takeUntil, shareReplay, map, filter } from "rxjs"; |
| 59 | +
|
| 60 | + const a = of("a"); |
| 61 | + const b = of("b"); |
| 62 | +
|
| 63 | + a.pipe(takeUntil(b), map(x => x), filter(x => !!x), shareReplay()); |
| 64 | + `, |
| 65 | + stripIndent` |
| 66 | + // namespace import with refCount true |
| 67 | + import * as Rx from "rxjs"; |
| 68 | +
|
| 69 | + const a = Rx.of("a"); |
| 70 | + const b = Rx.of("b"); |
| 71 | +
|
| 72 | + a.pipe(Rx.shareReplay({ refCount: true }), Rx.takeUntil(b)); |
| 73 | + `, |
| 74 | + stripIndent` |
| 75 | + // shareReplay by itself |
| 76 | + import { of, shareReplay } from "rxjs"; |
| 77 | +
|
| 78 | + const a = of("a"); |
| 79 | +
|
| 80 | + a.pipe(shareReplay()); |
| 81 | + `, |
| 82 | + stripIndent` |
| 83 | + // unrelated |
| 84 | + import { of, takeUntil, toArray } from "rxjs"; |
| 85 | +
|
| 86 | + const a = of("a"); |
| 87 | + const b = of("b"); |
| 88 | +
|
| 89 | + a.pipe(takeUntil(b), toArray()); |
| 90 | + `, |
| 91 | + ], |
| 92 | + invalid: [ |
| 93 | + fromFixture( |
| 94 | + stripIndent` |
| 95 | + // without config |
| 96 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 97 | +
|
| 98 | + const a = of("a"); |
| 99 | + const b = of("b"); |
| 100 | +
|
| 101 | + a.pipe(shareReplay(), takeUntil(b)); |
| 102 | + ~~~~~~~~~~~ [forbidden] |
| 103 | + `, |
| 104 | + ), |
| 105 | + fromFixture( |
| 106 | + stripIndent` |
| 107 | + // with refCount false |
| 108 | + import { of, takeUntil, shareReplay } from "rxjs"; |
| 109 | +
|
| 110 | + const a = of("a"); |
| 111 | + const b = of("b"); |
| 112 | +
|
| 113 | + a.pipe(shareReplay({ refCount: false }), takeUntil(b)); |
| 114 | + ~~~~~~~~~~~ [forbidden] |
| 115 | + `, |
| 116 | + ), |
| 117 | + fromFixture( |
| 118 | + stripIndent` |
| 119 | + // with operators in between |
| 120 | + import { of, takeUntil, shareReplay, map, filter } from "rxjs"; |
| 121 | +
|
| 122 | + const a = of("a"); |
| 123 | + const b = of("b"); |
| 124 | +
|
| 125 | + a.pipe(shareReplay(), map(x => x), filter(x => !!x), takeUntil(b)); |
| 126 | + ~~~~~~~~~~~ [forbidden] |
| 127 | + `, |
| 128 | + ), |
| 129 | + fromFixture( |
| 130 | + stripIndent` |
| 131 | + // namespace import |
| 132 | + import * as Rx from "rxjs"; |
| 133 | +
|
| 134 | + const a = Rx.of("a"); |
| 135 | + const b = Rx.of("b"); |
| 136 | +
|
| 137 | + a.pipe(Rx.shareReplay(), Rx.takeUntil(b)); |
| 138 | + ~~~~~~~~~~~~~~ [forbidden] |
| 139 | + `, |
| 140 | + ), |
| 141 | + ], |
| 142 | +}); |
0 commit comments