Skip to content

Commit

Permalink
fix(eslint-plugin): explicit-module-boundary-types
Browse files Browse the repository at this point in the history
Exit early when the type of the ancestor of the node being checked is
not a return statement.
  • Loading branch information
ifiokjr committed May 26, 2020
1 parent 89a4f07 commit 9b37ff0
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts
Expand Up @@ -366,34 +366,31 @@ function ancestorHasReturnType(
ancestor: TSESTree.Node | undefined,
options: Options,
): boolean {
// Exit early if this ancestor is not a ReturnStatement.
if (ancestor?.type !== AST_NODE_TYPES.ReturnStatement) {
return false;
}

// This boolean tells the `isValidFunctionReturnType` that it is being called
// by an ancestor check.
const isParentCheck = true;

// Has a valid type been found in any of the ancestors.
let hasType = false;

while (ancestor) {
switch (ancestor.type) {
case AST_NODE_TYPES.ArrowFunctionExpression:
case AST_NODE_TYPES.FunctionExpression:
hasType =
return (
isValidFunctionExpressionReturnType(ancestor, options) ||
isValidFunctionReturnType(ancestor, options, isParentCheck);
break;
isValidFunctionReturnType(ancestor, options, isParentCheck)
);
case AST_NODE_TYPES.FunctionDeclaration:
hasType = isValidFunctionReturnType(ancestor, options, isParentCheck);
break;
}

if (hasType) {
return hasType;
return isValidFunctionReturnType(ancestor, options, isParentCheck);
}

ancestor = ancestor.parent;
}

return hasType;
return false;
}

export {
Expand Down

0 comments on commit 9b37ff0

Please sign in to comment.