@@ -38,10 +38,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
38
38
import { of } from "rxjs";
39
39
const a = of("a");
40
40
a.toPromise().then(value => console.log(value));
41
- ~~~~~~~~~ [forbidden suggest 0 1]
41
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
42
42
` ,
43
43
{
44
44
suggestions : [
45
+ {
46
+ messageId : 'suggestLastValueFromWithDefault' ,
47
+ output : stripIndent `
48
+ // observable toPromise
49
+ import { of, lastValueFrom } from "rxjs";
50
+ const a = of("a");
51
+ lastValueFrom(a, { defaultValue: undefined }).then(value => console.log(value));
52
+ ` ,
53
+ } ,
45
54
{
46
55
messageId : 'suggestLastValueFrom' ,
47
56
output : stripIndent `
@@ -69,10 +78,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
69
78
import { Subject } from "rxjs";
70
79
const a = new Subject<string>();
71
80
a.toPromise().then(value => console.log(value));
72
- ~~~~~~~~~ [forbidden suggest 0 1]
81
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
73
82
` ,
74
83
{
75
84
suggestions : [
85
+ {
86
+ messageId : 'suggestLastValueFromWithDefault' ,
87
+ output : stripIndent `
88
+ // subject toPromise
89
+ import { Subject, lastValueFrom } from "rxjs";
90
+ const a = new Subject<string>();
91
+ lastValueFrom(a, { defaultValue: undefined }).then(value => console.log(value));
92
+ ` ,
93
+ } ,
76
94
{
77
95
messageId : 'suggestLastValueFrom' ,
78
96
output : stripIndent `
@@ -102,11 +120,22 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
102
120
a
103
121
.foo$
104
122
.toPromise().then(value => console.log(value))
105
- ~~~~~~~~~ [forbidden suggest 0 1]
123
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
106
124
.catch(error => console.error(error));
107
125
` ,
108
126
{
109
127
suggestions : [
128
+ {
129
+ messageId : 'suggestLastValueFromWithDefault' ,
130
+ output : stripIndent `
131
+ // weird whitespace
132
+ import { of, lastValueFrom } from "rxjs";
133
+ const a = { foo$: of("a") };
134
+ lastValueFrom(a
135
+ .foo$, { defaultValue: undefined }).then(value => console.log(value))
136
+ .catch(error => console.error(error));
137
+ ` ,
138
+ } ,
110
139
{
111
140
messageId : 'suggestLastValueFrom' ,
112
141
output : stripIndent `
@@ -138,10 +167,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
138
167
import { lastValueFrom as lvf, of } from "rxjs";
139
168
const a = of("a");
140
169
a.toPromise().then(value => console.log(value));
141
- ~~~~~~~~~ [forbidden suggest 0 1]
170
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
142
171
` ,
143
172
{
144
173
suggestions : [
174
+ {
175
+ messageId : 'suggestLastValueFromWithDefault' ,
176
+ output : stripIndent `
177
+ // lastValueFrom already imported
178
+ import { lastValueFrom as lvf, of } from "rxjs";
179
+ const a = of("a");
180
+ lvf(a, { defaultValue: undefined }).then(value => console.log(value));
181
+ ` ,
182
+ } ,
145
183
{
146
184
messageId : 'suggestLastValueFrom' ,
147
185
output : stripIndent `
@@ -170,10 +208,21 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
170
208
171
209
const a = fromFetch("https://api.some.com");
172
210
a.toPromise().then(value => console.log(value));
173
- ~~~~~~~~~ [forbidden suggest 0 1]
211
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
174
212
` ,
175
213
{
176
214
suggestions : [
215
+ {
216
+ messageId : 'suggestLastValueFromWithDefault' ,
217
+ output : stripIndent `
218
+ // rxjs not already imported
219
+ import { fromFetch } from "rxjs/fetch";
220
+ import { lastValueFrom } from "rxjs";
221
+
222
+ const a = fromFetch("https://api.some.com");
223
+ lastValueFrom(a, { defaultValue: undefined }).then(value => console.log(value));
224
+ ` ,
225
+ } ,
177
226
{
178
227
messageId : 'suggestLastValueFrom' ,
179
228
output : stripIndent `
@@ -205,10 +254,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
205
254
import * as Rx from "rxjs";
206
255
const a = Rx.of("a");
207
256
a.toPromise().then(value => console.log(value));
208
- ~~~~~~~~~ [forbidden suggest 0 1]
257
+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
209
258
` ,
210
259
{
211
260
suggestions : [
261
+ {
262
+ messageId : 'suggestLastValueFromWithDefault' ,
263
+ output : stripIndent `
264
+ // namespace import
265
+ import * as Rx from "rxjs";
266
+ const a = Rx.of("a");
267
+ Rx.lastValueFrom(a, { defaultValue: undefined }).then(value => console.log(value));
268
+ ` ,
269
+ } ,
212
270
{
213
271
messageId : 'suggestLastValueFrom' ,
214
272
output : stripIndent `
0 commit comments