Skip to content

Commit

Permalink
feat(scope): Add allowSubscribe option.
Browse files Browse the repository at this point in the history
Closes #100.
  • Loading branch information
cartant committed Jun 11, 2019
1 parent 9d637f2 commit 8caa4db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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/no-unsafe-scope/default/tslint.json\"",
"test:debug": "tslint --test \"./test/v6/fixtures/no-unsafe-scope/disallow/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
5 changes: 5 additions & 0 deletions source/rules/rxjsNoUnsafeScopeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ class Walker extends ScopeWalker {
options.allowProperties !== undefined
? options.allowProperties
: this.allowProperties;
this.allowSubscribe =
options.allowSubscribe !== undefined
? options.allowSubscribe
: this.allowSubscribe;
this.allowTap =
options.allowTap !== undefined ? options.allowTap : this.allowTap;
}
this.knownNames = this.allowSubscribe ? {} : { subscribe: true };
}

protected visitNode(node: ts.Node): void {
Expand Down
8 changes: 7 additions & 1 deletion source/support/scope-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { knownOperators, knownPipeableOperators } from "./knowns";
export class ScopeWalker extends Lint.ProgramAwareRuleWalker {
protected callbackMap: Map<ts.Node, string> = new Map<ts.Node, string>();
protected callbackStack: (ts.ArrowFunction | ts.FunctionExpression)[] = [];
protected knownNames: Record<string, boolean> = {};

protected visitArrowFunction(node: ts.ArrowFunction): void {
if (this.callbackMap.has(node)) {
Expand All @@ -33,7 +34,12 @@ export class ScopeWalker extends Lint.ProgramAwareRuleWalker {
name = propertyName.getText();
}

if (name && (knownOperators[name] || knownPipeableOperators[name])) {
if (
name &&
(this.knownNames[name] ||
knownOperators[name] ||
knownPipeableOperators[name])
) {
const callbacks = args.filter(
arg => tsutils.isArrowFunction(arg) || tsutils.isFunctionExpression(arg)
);
Expand Down

0 comments on commit 8caa4db

Please sign in to comment.