Skip to content

Commit

Permalink
feat: Add failure for Notification generics.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 6, 2019
1 parent 588b78f commit 115a0ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"test": "yarn run lint && yarn run test:build && yarn run test:mocha && yarn run test:tslint-v5 && yarn run test:tslint-v6 && yarn run test:tslint-v6-compat",
"test:build": "yarn run test:clean && tsc -p tsconfig.json",
"test:clean": "rimraf build",
"test:debug": "tslint --test ./test/v6/fixtures/issues/96/tslint.json",
"test:debug": "tslint --test ./test/v6/fixtures/no-explicit-generics/**/tslint.json",
"test:issues": "yarn run test:clean && tsc -p tsconfig.json && tslint --test ./test/v6/fixtures/issues/**/tslint.json",
"test:mocha": "mocha build/**/*-spec.js",
"test:tslint-v5": "yarn --cwd ./test/v5 install && yarn --cwd ./test/v5 upgrade && tslint --test ./test/v5/fixtures/**/tslint.json",
Expand Down
15 changes: 14 additions & 1 deletion source/rules/rxjsNoExplicitGenericsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import * as Lint from "tslint";
import * as tsutils from "tsutils";
import * as ts from "typescript";
import { tsquery } from "@phenomnomnominal/tsquery";

Expand Down Expand Up @@ -41,10 +42,22 @@ export class Rule extends Lint.Rules.AbstractRule {
identifiers.push(
...(tsquery(
sourceFile,
`NewExpression[typeArguments.length > 0] > Identifier[name="BehaviorSubject"]`
`NewExpression[typeArguments.length>0] > Identifier[name="BehaviorSubject"]`
) as ts.Identifier[])
);

const notificationIdentifiers = tsquery(
sourceFile,
`NewExpression[typeArguments.length>0] > Identifier[name="Notification"]`
) as ts.Identifier[];
identifiers.push(
...notificationIdentifiers.filter(identifier => {
const newExpression = identifier.parent as ts.NewExpression;
const [arg] = newExpression.arguments;
return tsutils.isStringLiteral(arg) && arg.text === "N";
})
);

return identifiers.map(
identifier =>
new Lint.RuleFailure(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BehaviorSubject, from, of } from "rxjs";
import { BehaviorSubject, from, of, Notification } from "rxjs";
import { scan } from "rxjs/operators";

const a = of(42, 54);
Expand All @@ -25,4 +25,10 @@ const h = of<number>(42, 54);
~~ [no-explicit-generics]
const i = of(42, 54);

const j = new Notification<number>("N", 42);
~~~~~~~~~~~~ [no-explicit-generics]
const k = new Notification("N", 42);
const l = new Notification<number>("E", undefined, "Kaboom!");
const m = new Notification<number>("C");

[no-explicit-generics]: Explicit generic type arguments are forbidden

0 comments on commit 115a0ba

Please sign in to comment.