@@ -28,17 +28,197 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
28
28
import { of } from "rxjs";
29
29
const a = of("a");
30
30
a.toPromise().then(value => console.log(value));
31
- ~~~~~~~~~ [forbidden]
31
+ ~~~~~~~~~ [forbidden suggest 0 1 ]
32
32
` ,
33
+ {
34
+ suggestions : [
35
+ {
36
+ messageId : 'suggestLastValueFrom' ,
37
+ output : stripIndent `
38
+ // observable toPromise
39
+ import { of, lastValueFrom } from "rxjs";
40
+ const a = of("a");
41
+ lastValueFrom(a).then(value => console.log(value));
42
+ ` ,
43
+ } ,
44
+ {
45
+ messageId : 'suggestFirstValueFrom' ,
46
+ output : stripIndent `
47
+ // observable toPromise
48
+ import { of, firstValueFrom } from "rxjs";
49
+ const a = of("a");
50
+ firstValueFrom(a).then(value => console.log(value));
51
+ ` ,
52
+ } ,
53
+ ] ,
54
+ } ,
33
55
) ,
34
56
fromFixture (
35
57
stripIndent `
36
58
// subject toPromise
37
59
import { Subject } from "rxjs";
38
60
const a = new Subject<string>();
39
61
a.toPromise().then(value => console.log(value));
40
- ~~~~~~~~~ [forbidden]
62
+ ~~~~~~~~~ [forbidden suggest 0 1 ]
41
63
` ,
64
+ {
65
+ suggestions : [
66
+ {
67
+ messageId : 'suggestLastValueFrom' ,
68
+ output : stripIndent `
69
+ // subject toPromise
70
+ import { Subject, lastValueFrom } from "rxjs";
71
+ const a = new Subject<string>();
72
+ lastValueFrom(a).then(value => console.log(value));
73
+ ` ,
74
+ } ,
75
+ {
76
+ messageId : 'suggestFirstValueFrom' ,
77
+ output : stripIndent `
78
+ // subject toPromise
79
+ import { Subject, firstValueFrom } from "rxjs";
80
+ const a = new Subject<string>();
81
+ firstValueFrom(a).then(value => console.log(value));
82
+ ` ,
83
+ } ,
84
+ ] ,
85
+ } ,
86
+ ) ,
87
+ fromFixture (
88
+ stripIndent `
89
+ // weird whitespace
90
+ import { of } from "rxjs";
91
+ const a = { foo$: of("a") };
92
+ a
93
+ .foo$
94
+ .toPromise().then(value => console.log(value))
95
+ ~~~~~~~~~ [forbidden suggest 0 1]
96
+ .catch(error => console.error(error));
97
+ ` ,
98
+ {
99
+ suggestions : [
100
+ {
101
+ messageId : 'suggestLastValueFrom' ,
102
+ output : stripIndent `
103
+ // weird whitespace
104
+ import { of, lastValueFrom } from "rxjs";
105
+ const a = { foo$: of("a") };
106
+ lastValueFrom(a
107
+ .foo$).then(value => console.log(value))
108
+ .catch(error => console.error(error));
109
+ ` ,
110
+ } ,
111
+ {
112
+ messageId : 'suggestFirstValueFrom' ,
113
+ output : stripIndent `
114
+ // weird whitespace
115
+ import { of, firstValueFrom } from "rxjs";
116
+ const a = { foo$: of("a") };
117
+ firstValueFrom(a
118
+ .foo$).then(value => console.log(value))
119
+ .catch(error => console.error(error));
120
+ ` ,
121
+ } ,
122
+ ] ,
123
+ } ,
124
+ ) ,
125
+ fromFixture (
126
+ stripIndent `
127
+ // lastValueFrom already imported
128
+ import { lastValueFrom as lvf, of } from "rxjs";
129
+ const a = of("a");
130
+ a.toPromise().then(value => console.log(value));
131
+ ~~~~~~~~~ [forbidden suggest 0 1]
132
+ ` ,
133
+ {
134
+ suggestions : [
135
+ {
136
+ messageId : 'suggestLastValueFrom' ,
137
+ output : stripIndent `
138
+ // lastValueFrom already imported
139
+ import { lastValueFrom as lvf, of } from "rxjs";
140
+ const a = of("a");
141
+ lvf(a).then(value => console.log(value));
142
+ ` ,
143
+ } ,
144
+ {
145
+ messageId : 'suggestFirstValueFrom' ,
146
+ output : stripIndent `
147
+ // lastValueFrom already imported
148
+ import { lastValueFrom as lvf, of, firstValueFrom } from "rxjs";
149
+ const a = of("a");
150
+ firstValueFrom(a).then(value => console.log(value));
151
+ ` ,
152
+ } ,
153
+ ] ,
154
+ } ,
155
+ ) ,
156
+ fromFixture (
157
+ stripIndent `
158
+ // rxjs not already imported
159
+ import { fromFetch } from "rxjs/fetch";
160
+
161
+ const a = fromFetch("https://api.some.com");
162
+ a.toPromise().then(value => console.log(value));
163
+ ~~~~~~~~~ [forbidden suggest 0 1]
164
+ ` ,
165
+ {
166
+ suggestions : [
167
+ {
168
+ messageId : 'suggestLastValueFrom' ,
169
+ output : stripIndent `
170
+ // rxjs not already imported
171
+ import { fromFetch } from "rxjs/fetch";
172
+ import { lastValueFrom } from "rxjs";
173
+
174
+ const a = fromFetch("https://api.some.com");
175
+ lastValueFrom(a).then(value => console.log(value));
176
+ ` ,
177
+ } ,
178
+ {
179
+ messageId : 'suggestFirstValueFrom' ,
180
+ output : stripIndent `
181
+ // rxjs not already imported
182
+ import { fromFetch } from "rxjs/fetch";
183
+ import { firstValueFrom } from "rxjs";
184
+
185
+ const a = fromFetch("https://api.some.com");
186
+ firstValueFrom(a).then(value => console.log(value));
187
+ ` ,
188
+ } ,
189
+ ] ,
190
+ } ,
191
+ ) ,
192
+ fromFixture (
193
+ stripIndent `
194
+ // namespace import
195
+ import * as Rx from "rxjs";
196
+ const a = Rx.of("a");
197
+ a.toPromise().then(value => console.log(value));
198
+ ~~~~~~~~~ [forbidden suggest 0 1]
199
+ ` ,
200
+ {
201
+ suggestions : [
202
+ {
203
+ messageId : 'suggestLastValueFrom' ,
204
+ output : stripIndent `
205
+ // namespace import
206
+ import * as Rx from "rxjs";
207
+ const a = Rx.of("a");
208
+ Rx.lastValueFrom(a).then(value => console.log(value));
209
+ ` ,
210
+ } ,
211
+ {
212
+ messageId : 'suggestFirstValueFrom' ,
213
+ output : stripIndent `
214
+ // namespace import
215
+ import * as Rx from "rxjs";
216
+ const a = Rx.of("a");
217
+ Rx.firstValueFrom(a).then(value => console.log(value));
218
+ ` ,
219
+ } ,
220
+ ] ,
221
+ } ,
42
222
) ,
43
223
] ,
44
224
} ) ;
0 commit comments