Skip to content

Commit

Permalink
fix(nested): Fix false positive.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Apr 20, 2019
1 parent 6630f3f commit a57f938
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions source/rules/rxjsNoNestedSubscribeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Rule extends Lint.Rules.TypedRule {
const failures: Lint.RuleFailure[] = [];
const typeChecker = program.getTypeChecker();

const subscribeQuery = `CallExpression PropertyAccessExpression[name.name="subscribe"]`;
const subscribeQuery = `CallExpression > PropertyAccessExpression[name.name="subscribe"]`;
const propertyAccessExpressions = tsquery(sourceFile, subscribeQuery);
propertyAccessExpressions.forEach(node => {
const propertyAccessExpression = node as ts.PropertyAccessExpression;
Expand All @@ -41,23 +41,25 @@ export class Rule extends Lint.Rules.TypedRule {
);
if (couldBeType(type, "Observable")) {
callExpression.arguments.forEach(arg => {
const propertyAccessExpressions = tsquery(arg, subscribeQuery);
propertyAccessExpressions.forEach(node => {
const propertyAccessExpression = node as ts.PropertyAccessExpression;
const type = typeChecker.getTypeAtLocation(
propertyAccessExpression.expression
);
if (couldBeType(type, "Observable")) {
const { name } = propertyAccessExpression;
failures.push(
new Lint.RuleFailure(
sourceFile,
name.getStart(),
name.getStart() + name.getWidth(),
Rule.FAILURE_STRING,
this.ruleName
)
const innerPropertyAccessExpressions = tsquery(arg, subscribeQuery);
innerPropertyAccessExpressions.forEach(node => {
const innerPropertyAccessExpression = node as ts.PropertyAccessExpression;
if (innerPropertyAccessExpression !== propertyAccessExpression) {
const type = typeChecker.getTypeAtLocation(
innerPropertyAccessExpression.expression
);
if (couldBeType(type, "Observable")) {
const { name } = innerPropertyAccessExpression;
failures.push(
new Lint.RuleFailure(
sourceFile,
name.getStart(),
name.getStart() + name.getWidth(),
Rule.FAILURE_STRING,
this.ruleName
)
);
}
}
});
});
Expand Down

0 comments on commit a57f938

Please sign in to comment.