diff --git a/package.json b/package.json index 0cf50d62..ab5a5195 100644 --- a/package.json +++ b/package.json @@ -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\"", diff --git a/source/rules/rxjsNoUnsafeScopeRule.ts b/source/rules/rxjsNoUnsafeScopeRule.ts index cedabccf..c6efdc83 100644 --- a/source/rules/rxjsNoUnsafeScopeRule.ts +++ b/source/rules/rxjsNoUnsafeScopeRule.ts @@ -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 { diff --git a/source/support/scope-walker.ts b/source/support/scope-walker.ts index 6ae4c569..0bca1299 100644 --- a/source/support/scope-walker.ts +++ b/source/support/scope-walker.ts @@ -11,6 +11,7 @@ import { knownOperators, knownPipeableOperators } from "./knowns"; export class ScopeWalker extends Lint.ProgramAwareRuleWalker { protected callbackMap: Map = new Map(); protected callbackStack: (ts.ArrowFunction | ts.FunctionExpression)[] = []; + protected knownNames: Record = {}; protected visitArrowFunction(node: ts.ArrowFunction): void { if (this.callbackMap.has(node)) { @@ -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) );