Query module ImplicitReturn

name
Not all control paths return a value
description
Functions where some execution paths return an explicit value while others “fall off” the end of the function and return ‘undefined’ are hard to maintain and use.
kind
problem
problem.severity
recommendation
id
js/implicit-return
tags
maintainability
precision
medium

Imports

RestrictedLocations

Provides classes for restricting the locations reported for program elements.

javascript

Provides classes for working with JavaScript programs, as well as JSON, YAML and HTML.

Predicates

getAFallThroughStmt

Gets a fall-through statement in function f, that is, a statement that is reachable, does not have a successor statement inside the function, isn’t a throw or a return, and isn’t contained in a finally block.

getFirstExplicitReturn

Gets the lexically first explicit return statement in function f.

isDualUseConstructor

Holds if f is a dual-use constructor, that is, is a function that is meant to be invoked with new only, but guards against the case where it is invoked as a plain function.

isThrowOrReturn

Holds if s is a statement that terminates execution of the surrounding method, either by returning or throwing an exception. As a special case, we include calls to functions whose name contains "throw".

numRet

Gets the number of return statements in function f, assuming there is at least one.

Classes

ValueReturn

A return statement with an operand (that is, not just return;).