-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add options to Angular takeUntil rule.
- Loading branch information
Showing
8 changed files
with
182 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/v6/fixtures/prefer-angular-takeuntil/alias/fixture.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Component, OnDestroy } from "@angular/core"; | ||
import { of, Subject } from "rxjs"; | ||
import { switchMap, takeUntil } from "rxjs/operators"; | ||
|
||
const a = of("a"); | ||
const b = of("b"); | ||
const c = of("c"); | ||
const d = of("d"); | ||
|
||
const someAlias = takeUntil; | ||
|
||
@Component({ | ||
selector: "component-with-alias" | ||
}) | ||
class CorrectComponent implements OnDestroy { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b), | ||
someAlias(this.destroy) | ||
).subscribe(); | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: "component-without-alias" | ||
}) | ||
class NoTakeUntilComponent { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
const { destroy } = this; | ||
a.pipe( | ||
switchMap(_ => b) | ||
).subscribe(); | ||
~~~~~~~~~ [prefer-takeuntil] | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
[prefer-takeuntil]: Subscribing without takeUntil is forbidden |
13 changes: 13 additions & 0 deletions
13
test/v6/fixtures/prefer-angular-takeuntil/alias/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"lib": ["es2015"], | ||
"noEmit": true, | ||
"paths": { | ||
"rxjs": ["../../node_modules/rxjs"] | ||
}, | ||
"skipLibCheck": true, | ||
"target": "es5" | ||
}, | ||
"include": ["fixture.ts"] | ||
} |
13 changes: 13 additions & 0 deletions
13
test/v6/fixtures/prefer-angular-takeuntil/alias/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"jsRules": {}, | ||
"rules": { | ||
"rxjs-prefer-angular-takeuntil": { | ||
"options": [{ | ||
"alias": ["someAlias"] | ||
}], | ||
"severity": "error" | ||
} | ||
}, | ||
"rulesDirectory": "../../../../../build/rules" | ||
} |
35 changes: 35 additions & 0 deletions
35
test/v6/fixtures/prefer-angular-takeuntil/no-destroy/fixture.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Component } from "@angular/core"; | ||
import { NEVER, of, Subject } from "rxjs"; | ||
import { switchMap, takeUntil } from "rxjs/operators"; | ||
|
||
const a = of("a"); | ||
const b = of("b"); | ||
const c = of("c"); | ||
const d = of("d"); | ||
|
||
@Component({ | ||
selector: "correct-component" | ||
}) | ||
class CorrectComponent implements OnDestroy { | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b), | ||
takeUntil(NEVER) | ||
).subscribe(); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: "no-takeuntil-component" | ||
}) | ||
class NoTakeUntilComponent { | ||
someMethod() { | ||
const { destroy } = this; | ||
a.pipe( | ||
switchMap(_ => b) | ||
).subscribe(); | ||
~~~~~~~~~ [prefer-takeuntil] | ||
} | ||
} | ||
|
||
[prefer-takeuntil]: Subscribing without takeUntil is forbidden |
13 changes: 13 additions & 0 deletions
13
test/v6/fixtures/prefer-angular-takeuntil/no-destroy/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"lib": ["es2015"], | ||
"noEmit": true, | ||
"paths": { | ||
"rxjs": ["../../node_modules/rxjs"] | ||
}, | ||
"skipLibCheck": true, | ||
"target": "es5" | ||
}, | ||
"include": ["fixture.ts"] | ||
} |
13 changes: 13 additions & 0 deletions
13
test/v6/fixtures/prefer-angular-takeuntil/no-destroy/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"jsRules": {}, | ||
"rules": { | ||
"rxjs-prefer-angular-takeuntil": { | ||
"options": [{ | ||
"checkDestroy": false | ||
}], | ||
"severity": "error" | ||
} | ||
}, | ||
"rulesDirectory": "../../../../../build/rules" | ||
} |