Skip to content

Commit

Permalink
feat(rxjs-no-subject-unsubscribe): Add rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jul 15, 2017
1 parent 34a455e commit acc1885
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 106 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### What is it?

`rxjs-tslint-rules` is small set of TSLint rules to help manage projects that use `rxjs/add/...` imports.
`rxjs-tslint-rules` is small set of TSLint rules to help manage projects that use `rxjs/add/...` imports and to highlight other potential problems.

### Why might I need it?

Expand All @@ -24,7 +24,7 @@ TypeScript will see the merged declarations in all modules, making it difficult

This can cause problems, as whether or not `Observable` is patched then depends upon the order in which the modules are executed.

The rules in this package can be used to highlight missing - or unused - imports.
The rules in this package can be used to highlight missing - or unused - imports and other potential problems with RxJS.

## Install

Expand Down Expand Up @@ -54,6 +54,7 @@ The package includes the following rules:
| --- | --- | --- |
| `rxjs-add` | Enforces the importation of patched observables and operators used in the module. | See below |
| `rxjs-no-add` | Disallows the importation of patched observables and operators. | None |
| `rxjs-no-subject-unsubscribe` | Disallows the calling of `unsubscribe` directly upon `Subject` instances. For an explanation of why this can be a problem, see [this](https://stackoverflow.com/a/45112125/6680611) Stack Overflow answer. | None |
| `rxjs-no-unused-add` | Disallows the importation of patched observables or operators that are not used in the module. | None |
| `rxjs-prefer-add` | Disallows the importation of `rxjs` or `rxjs/Rx`. | None |

Expand Down
4 changes: 4 additions & 0 deletions fixtures/async-subject-with-unsubscribe/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AsyncSubject } from "rxjs/AsyncSubject";

const subject = new AsyncSubject<number>();
subject.unsubscribe();
13 changes: 13 additions & 0 deletions fixtures/async-subject-with-unsubscribe/tsconfig.json
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"]
}
8 changes: 8 additions & 0 deletions fixtures/async-subject-with-unsubscribe/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"rxjs-no-subject-unsubscribe": { "severity": "error" }
},
"rulesDirectory": "../../build/rules"
}
4 changes: 4 additions & 0 deletions fixtures/subject-with-unsubscribe/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Subject } from "rxjs/Subject";

const subject = new Subject<number>();
subject.unsubscribe();
13 changes: 13 additions & 0 deletions fixtures/subject-with-unsubscribe/tsconfig.json
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"]
}
8 changes: 8 additions & 0 deletions fixtures/subject-with-unsubscribe/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"rxjs-no-subject-unsubscribe": { "severity": "error" }
},
"rulesDirectory": "../../build/rules"
}
5 changes: 5 additions & 0 deletions fixtures/subject-without-unsubscribe/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Subject } from "rxjs/Subject";

const subject = new Subject<number>();
const subscription = subject.subscribe();
subscription.unsubscribe();
13 changes: 13 additions & 0 deletions fixtures/subject-without-unsubscribe/tsconfig.json
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"]
}
8 changes: 8 additions & 0 deletions fixtures/subject-without-unsubscribe/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultSeverity": "error",
"jsRules": {},
"rules": {
"rxjs-no-subject-unsubscribe": { "severity": "error" }
},
"rulesDirectory": "../../build/rules"
}
Loading

0 comments on commit acc1885

Please sign in to comment.