Skip to content

Commit

Permalink
fix(unsafe-catch): Consider the caught param safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Apr 27, 2019
1 parent c47a326 commit 86211bb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions source/rules/rxjsNoUnsafeCatchRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export class Walker extends Lint.ProgramAwareRuleWalker {
if (name) {
switch (name.getText()) {
case "catch":
this.addFailureAtNode(name, Rule.FAILURE_STRING);
if (isUnsafe(parent.arguments)) {
this.addFailureAtNode(name, Rule.FAILURE_STRING);
}
break;
case "pipe":
this.walkPipedOperators(parent);
Expand All @@ -141,8 +143,9 @@ export class Walker extends Lint.ProgramAwareRuleWalker {
private walkPipedOperators(node: ts.CallExpression): void {
node.arguments.forEach(arg => {
if (tsutils.isCallExpression(arg)) {
const { expression } = arg;
const { arguments: args, expression } = arg;
if (
isUnsafe(args) &&
tsutils.isIdentifier(expression) &&
expression.getText() === "catchError"
) {
Expand All @@ -166,3 +169,10 @@ export class Walker extends Lint.ProgramAwareRuleWalker {
});
}
}

function isUnsafe([arg]: ts.NodeArray<ts.Expression>): boolean {
if (tsutils.isFunctionDeclaration(arg) || tsutils.isArrowFunction(arg)) {
return arg.parameters.length < 2;
}
return false;
}

0 comments on commit 86211bb

Please sign in to comment.