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?
- Makes the exit point of every function visible without scanning for implicit fall-through.
- Keeps void functions consistent with functions that return values — both have an explicit return.
- 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.
| Option | Type | Default | Description |
|---|---|---|---|
excludeArrowFunctions | boolean | false | Skip arrow function expressions. |
excludeConstructors | boolean | false | Skip class constructors. |
excludeSetters | boolean | false | Skip setter methods. |
ignoreFiles | string[] | [] | 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
returnwith 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.