Return value of function without any return statement should not be used

  • MISSING_RETURN_VALUE
  • Error
  • Medium
  • No tags

This rule applies when return value is used even though the function has no return statement.

It might be intentional, but it often is a programmer's mistake forgetting return statement.

Note: Not applied for the following idiomatic cases where the return value is not in actual use:

  1. Empty function
  2. Error function, which always throws exception
  3. IIFE(Immediately-Invoked Function Expression) call
  4. Return value is chained to another return or throw statement
  5. Return value is used as an argument of void operator

Noncompliant Code Example

function add(x, y) {
    x + y;
}
var sum = add(1, 2); // MISSING_RETURN_VALUE alarm because function 'add' does not return a value.

Compliant Code Example

function add(x, y) {
    return x + y;
}
var sum = add(1, 2);

Version

This rule was introduced in DeepScan 1.0.0-alpha.