All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3801.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

Unlike strongly typed languages, JavaScript does not enforce a return type on a function. This means that different paths through a function can return different types of values, which can be very confusing to the user and significantly harder to maintain.

In particular a function, in JavaScript, will return undefined in any of the following cases:

  • It exits without a return statement.
  • It executes a return with no value.

This rule verifies that return values are either always or never specified for each path through a function.

Noncompliant code example

function foo(a) { // Noncompliant, function exits without "return"
  if (a == 1) {
    return true;
  }
}

Compliant solution

function foo(a) {
  if (a == 1) {
    return true;
  }
  return false;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy