No Useless Return

ID

javascript.no_useless_return

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

JavaScript

Tags

code-smell, simplification

Description

Reports a bare return; (with no expression) as the last statement of a function body:

function f() {
  doStuff();
  return;        // useless — falling off the end already returns undefined
}

const g = () => {
  doStuff();
  return;        // useless
};

Rationale

A function that "runs off the end" already returns undefined. The trailing return; adds two characters and a line of code without changing behaviour. It also creates a small but real cost when reading the code — the reader has to confirm there is no missing expression after return.

Remediation

Delete the trailing return;:

function f() {
  doStuff();
}

const g = () => {
  doStuff();
};

Notes

The rule deliberately fires only on the trailing position. A return; inside an if branch, a loop or a switch case usually skips code that would otherwise execute and is not redundant — it is not reported.

A return value; (with an expression) is also not reported. This rule is about the empty form only.

References