Skip to content

Commit

Permalink
fix(switchmap): Account for this, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jun 26, 2018
1 parent da69c17 commit 97546e4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/rules/rxjsNoUnsafeSwitchmapRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export class Walker extends Lint.ProgramAwareRuleWalker {

const [options] = this.getOptions();
if (options && (options.allow || options.disallow)) {

this.allowRegExp = Walker.createRegExp(options.allow);
this.disallowRegExp = Walker.createRegExp(options.disallow);
this.observableRegExp = new RegExp(options.observable || Walker.DEFAULT_OBSERVABLE, "i");
Expand All @@ -112,16 +111,22 @@ export class Walker extends Lint.ProgramAwareRuleWalker {
const { expression: propertyAccessExpression } = node;
if (tsutils.isPropertyAccessExpression(propertyAccessExpression)) {

const { expression: identifier } = propertyAccessExpression;
if (tsutils.isIdentifier(identifier)) {
const { expression: observableExpression } = propertyAccessExpression;

let observableIdentifier: ts.Identifier | undefined = undefined;
if (tsutils.isIdentifier(observableExpression)) {
observableIdentifier = observableExpression;
} else if (tsutils.isPropertyAccessExpression(observableExpression)) {
observableIdentifier = observableExpression.name;
}

if (observableIdentifier && this.observableRegExp.test(observableIdentifier.getText())) {

const propertyName = propertyAccessExpression.name.getText();
const identifierText = identifier.getText();
const typeChecker = this.getTypeChecker();
const type = typeChecker.getTypeAtLocation(identifier);
const type = typeChecker.getTypeAtLocation(observableExpression);

if (isReferenceType(type) &&
this.observableRegExp.test(identifierText) &&
Walker.METHODS_REGEXP.test(propertyName) &&
couldBeType(type.target, "Observable")) {

Expand Down

0 comments on commit 97546e4

Please sign in to comment.