DeepSource has joined Harness. Learn more
Scala logoScala/
SC-R1015

Redundant `else` in `else if`SC-R1015

Minor severityMinor
Anti-pattern categoryAnti-pattern

else in else if becomes redundant and can be dropped if the last statement under if's then block is a return statement. This improves code-readability and is easy to maintain.

Bad practice

if (/* some condition */) {
  // do something
  return someValue
} else if (/* some other condition */) {            // simplification - `else` can be dropped here
  // do something
  return otherValue
}
if (/* some condition */) {
  // do something
  return someValue
}

if (/* some other condition */) {
  // do something
  return otherValue
}