redline
LowDesignelse-after-return

else after return

else after return. else after a return. The early exit already handles the other case; drop the else and unindent.

This is how the comment reads inline, under the flagged line.

Why it matters

When the if branch returns, the else only adds indentation. Early returns keep the main path flat.

What to do

Drop the else and dedent its body.

Examples

Flagged
if (!user) {
  return null;
} else {
  return user.name;
}
Better
if (!user) return null;
return user.name;

What it catches

It reads the shape of the code: functions, blocks, loops and calls. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

function f(u) {
  if (!u) {
    return null;
  } else {
    return u.name;
  }
}
src/app.py
def f(u):
    if not u:
        return None
    else:
        return u.name

Left alone

function f(u) {
  if (!u) return null;
  return u.name;
}

Research

`else` after a branch that returns. It adds nesting for no reason.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "else-after-return"
    ],
    "severity": {
      "else-after-return": "medium"
    }
  }
}

Read the source or report a false positive.