@@ -32,6 +32,28 @@ ruleTester({ types: true }).run("prefer-composition", rule, {
32
32
}
33
33
` ,
34
34
} ,
35
+ {
36
+ code : stripIndent `
37
+ // composed component with private JavaScript property
38
+ import { Component, OnDestroy, OnInit } from "@angular/core";
39
+ import { of, Subscription } from "rxjs";
40
+
41
+ @Component({
42
+ selector: "composed-component",
43
+ template: "<span>{{ value }}</span>"
44
+ })
45
+ export class ComposedComponent implements OnInit, OnDestroy {
46
+ value: string;
47
+ #subscription = new Subscription();
48
+ ngOnInit() {
49
+ this.#subscription.add(of("foo").subscribe(value => this.value = value));
50
+ }
51
+ ngOnDestroy() {
52
+ this.#subscription.unsubscribe();
53
+ }
54
+ }
55
+ ` ,
56
+ } ,
35
57
{
36
58
code : stripIndent `
37
59
// variable composed component
@@ -47,7 +69,7 @@ ruleTester({ types: true }).run("prefer-composition", rule, {
47
69
private subscription = new Subscription();
48
70
ngOnInit() {
49
71
let subscription = of("foo").subscribe(value => this.value = value);
50
- this.subscription.add(subscription);1
72
+ this.subscription.add(subscription);
51
73
subscription = of("bar").subscribe(value => this.value = value);
52
74
this.subscription.add(subscription);
53
75
}
@@ -57,6 +79,31 @@ ruleTester({ types: true }).run("prefer-composition", rule, {
57
79
}
58
80
` ,
59
81
} ,
82
+ {
83
+ code : stripIndent `
84
+ // variable composed component with private JavaScript property
85
+ import { Component, OnDestroy, OnInit } from "@angular/core";
86
+ import { of, Subscription } from "rxjs";
87
+
88
+ @Component({
89
+ selector: "variable-composed-component",
90
+ template: "<span>{{ value }}</span>"
91
+ })
92
+ export class VariableComposedComponent implements OnInit, OnDestroy {
93
+ value: string;
94
+ #subscription = new Subscription();
95
+ ngOnInit() {
96
+ let subscription = of("foo").subscribe(value => this.value = value);
97
+ this.#subscription.add(subscription);
98
+ subscription = of("bar").subscribe(value => this.value = value);
99
+ this.#subscription.add(subscription);
100
+ }
101
+ ngOnDestroy() {
102
+ this.#subscription.unsubscribe();
103
+ }
104
+ }
105
+ ` ,
106
+ } ,
60
107
{
61
108
code : stripIndent `
62
109
// destructured composed component
@@ -145,6 +192,28 @@ ruleTester({ types: true }).run("prefer-composition", rule, {
145
192
}
146
193
`
147
194
) ,
195
+ fromFixture (
196
+ stripIndent `
197
+ // not unsubscribed component with private JavaScript property
198
+ import { Component, OnDestroy, OnInit } from "@angular/core";
199
+ import { of, Subscription } from "rxjs";
200
+
201
+ @Component({
202
+ selector: "not-unsubscribed-component",
203
+ template: "<span>{{ value }}</span>"
204
+ })
205
+ export class NotUnsubscribedComponent implements OnInit, OnDestroy {
206
+ value: string;
207
+ #subscription = new Subscription();
208
+ ~~~~~~~~~~~~~ [notUnsubscribed]
209
+ ngOnInit() {
210
+ this.#subscription.add(of("foo").subscribe(value => this.value = value));
211
+ }
212
+ ngOnDestroy() {
213
+ }
214
+ }
215
+ `
216
+ ) ,
148
217
fromFixture (
149
218
stripIndent `
150
219
// not destroyed component
@@ -165,6 +234,26 @@ ruleTester({ types: true }).run("prefer-composition", rule, {
165
234
}
166
235
`
167
236
) ,
237
+ fromFixture (
238
+ stripIndent `
239
+ // not destroyed component with Private JavaScript property
240
+ import { Component, OnDestroy, OnInit } from "@angular/core";
241
+ import { of, Subscription } from "rxjs";
242
+
243
+ @Component({
244
+ selector: "not-destroyed-component",
245
+ template: "<span>{{ value }}</span>"
246
+ })
247
+ export class NotDestroyedComponent implements OnInit {
248
+ ~~~~~~~~~~~~~~~~~~~~~ [notImplemented]
249
+ value: string;
250
+ #subscription = new Subscription();
251
+ ngOnInit() {
252
+ this.#subscription.add(of("foo").subscribe(value => this.value = value));
253
+ }
254
+ }
255
+ `
256
+ ) ,
168
257
fromFixture (
169
258
stripIndent `
170
259
// not declared
0 commit comments