Why is this an issue?

When a function has multiple return statements and returns the same value in more than one of them, it can lead to several potential problems:

This rule raises an issue when a function contains several return statements that all return the same value.

function f(a, g) { // Noncompliant: 'f' returns 'b' on two different return statements
  const b = 42;
  if (a) {
    g(a);
    return b;
  }
  return b;
}

To address this, you should refactor the function to use a single return statement with a variable storing the value to be returned. This way, the code becomes more concise, easier to understand, and reduces the likelihood of introducing errors when making changes in the future. By using a single return point, you can also enforce consistency and prevent unexpected return values.

function f(a, g) {
  const b = 42;
  if (a) {
    g(a);
  }
  return b;
}

Resources

Documentation