@@ -38,10 +38,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
3838 import { of } from "rxjs";
3939 const a = of("a");
4040 a.toPromise().then(value => console.log(value));
41- ~~~~~~~~~ [forbidden suggest 0 1]
41+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
4242 ` ,
4343 {
4444 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+ } ,
4554 {
4655 messageId : 'suggestLastValueFrom' ,
4756 output : stripIndent `
@@ -69,10 +78,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
6978 import { Subject } from "rxjs";
7079 const a = new Subject<string>();
7180 a.toPromise().then(value => console.log(value));
72- ~~~~~~~~~ [forbidden suggest 0 1]
81+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
7382 ` ,
7483 {
7584 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+ } ,
7694 {
7795 messageId : 'suggestLastValueFrom' ,
7896 output : stripIndent `
@@ -102,11 +120,22 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
102120 a
103121 .foo$
104122 .toPromise().then(value => console.log(value))
105- ~~~~~~~~~ [forbidden suggest 0 1]
123+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
106124 .catch(error => console.error(error));
107125 ` ,
108126 {
109127 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+ } ,
110139 {
111140 messageId : 'suggestLastValueFrom' ,
112141 output : stripIndent `
@@ -138,10 +167,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
138167 import { lastValueFrom as lvf, of } from "rxjs";
139168 const a = of("a");
140169 a.toPromise().then(value => console.log(value));
141- ~~~~~~~~~ [forbidden suggest 0 1]
170+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
142171 ` ,
143172 {
144173 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+ } ,
145183 {
146184 messageId : 'suggestLastValueFrom' ,
147185 output : stripIndent `
@@ -170,10 +208,21 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
170208
171209 const a = fromFetch("https://api.some.com");
172210 a.toPromise().then(value => console.log(value));
173- ~~~~~~~~~ [forbidden suggest 0 1]
211+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
174212 ` ,
175213 {
176214 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+ } ,
177226 {
178227 messageId : 'suggestLastValueFrom' ,
179228 output : stripIndent `
@@ -205,10 +254,19 @@ ruleTester({ types: true }).run('no-topromise', noTopromiseRule, {
205254 import * as Rx from "rxjs";
206255 const a = Rx.of("a");
207256 a.toPromise().then(value => console.log(value));
208- ~~~~~~~~~ [forbidden suggest 0 1]
257+ ~~~~~~~~~ [forbidden suggest 0 1 2 ]
209258 ` ,
210259 {
211260 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+ } ,
212270 {
213271 messageId : 'suggestLastValueFrom' ,
214272 output : stripIndent `
0 commit comments