-
-
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 option to check takeUntil within all angular entities (#116)
* feat: Add option to check takeUntil within all angular entities * fix: Renamed option to specify decorators when using which it is necessary to check class Co-authored-by: Vakhaniya Gennadiy <[email protected]>
- Loading branch information
Showing
6 changed files
with
218 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
131 changes: 131 additions & 0 deletions
131
test/v6/fixtures/prefer-angular-takeuntil/check-decorators/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,131 @@ | ||
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"); | ||
|
||
// COMPONENTS | ||
|
||
@Component({ | ||
selector: "correct-component" | ||
}) | ||
class CorrectComponent implements OnDestroy { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b), | ||
takeUntil(this.destroy) | ||
).subscribe(); | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: "no-next-component" | ||
}) | ||
class NoTakeUntilComponent { | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
).subscribe(); | ||
~~~~~~~~~ [prefer-takeuntil] | ||
} | ||
} | ||
|
||
// SERVICES | ||
|
||
@Injectable() | ||
class CorrectService implements OnDestroy { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
takeUntil(this.destroy) | ||
).subscribe(); | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
@Injectable() | ||
class NoTakeUntilService { | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
).subscribe(); | ||
~~~~~~~~~ [prefer-takeuntil] | ||
} | ||
} | ||
|
||
// PIPES | ||
|
||
@Pipe({ | ||
name: 'controlByName', | ||
}) | ||
class CorrectPipe implements OnDestroy { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
takeUntil(this.destroy) | ||
).subscribe(); | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
@Pipe({ | ||
name: 'controlByName', | ||
}) | ||
class NoTakeUntilPipe { | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
).subscribe(); | ||
~~~~~~~~~ [prefer-takeuntil] | ||
} | ||
} | ||
|
||
// DIRECTIVES | ||
|
||
@Directive({ | ||
selector: 'my-directive' | ||
}) | ||
class CorrectDirective implements OnDestroy { | ||
private destroy = new Subject<void>(); | ||
someMethod() { | ||
a.pipe( | ||
switchMap(_ => b) | ||
takeUntil(this.destroy) | ||
).subscribe(); | ||
} | ||
ngOnDestroy() { | ||
this.destroy.next(); | ||
this.destroy.complete(); | ||
} | ||
} | ||
|
||
|
||
@Directive({ | ||
selector: 'my-directive' | ||
}) | ||
class NoTakeUntilDirective { | ||
someMethod() { | ||
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/check-decorators/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"] | ||
} |
18 changes: 18 additions & 0 deletions
18
test/v6/fixtures/prefer-angular-takeuntil/check-decorators/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,18 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"jsRules": {}, | ||
"rules": { | ||
"rxjs-prefer-angular-takeuntil": { | ||
"options": [{ | ||
"checkDecorators": [ | ||
"Component", | ||
"Pipe", | ||
"Injectable", | ||
"Directive" | ||
] | ||
}], | ||
"severity": "error" | ||
} | ||
}, | ||
"rulesDirectory": "../../../../../build/rules" | ||
} |
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