Skip to main content

Require Explicit Return

Require an explicit return; at the end of void function bodies so every function signals its exit point.

Summary

The require-explicit-return rule reports any function, method, constructor, setter, or arrow function (with a block body) that has a void return and does not end with an explicit return; statement.

Functions that already return a value and concise arrow functions (no block body) are not affected.

Why Use This Rule?

  1. Makes the exit point of every function visible without scanning for implicit fall-through.
  2. Keeps void functions consistent with functions that return values — both have an explicit return.
  3. Prevents accidental omission where a return was intended but forgotten.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
excludeArrowFunctionsbooleanfalseSkip arrow function expressions.
excludeConstructorsbooleanfalseSkip class constructors.
excludeSettersbooleanfalseSkip setter methods.
ignoreFilesstring[][]File patterns to skip.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Warning fires on a function that returns a value in some branches — The rule scans the entire function body for any return with a value. If found, the function is treated as non-void and the rule does not fire. Mixed-return functions (some branches return a value, others do not) are skipped.
  • Concise arrows are not flagged — Arrow functions without a block body (e.g., (n) => n * 2) have an implicit return value and are not void.