Return of boolean expressions should not be wrapped into an if-then-else statement

  • squid : S1126

Return of boolean literal statements wrapped into if-then-else ones should be simplified.

For example, the following code:

if (someBooleanMethod()) {    // Non-Compliant
  return true;
} else {
  return false;
}

should be refactored into:

return someBooleanMethod();   // Compliant

and, the following code:

if (someBooleanMethod()) {    // Non-Compliant
  return false;
} else {
  return true;
}

should be refactored into:

return !someBooleanMethod();  // Compliant
Close