Redundant return at the end of a method
ID |
objectivec.maintainability.omit_redundant_control_flow |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Control Flow |
Language |
Objective-C |
Description
Reports a bare return; written as the last statement of a method or of a C function, i.e. immediately above the closing brace in column zero. A return; used as a guard inside an if, and a return that carries a value, are not reported.
Rationale
Control already leaves the method at the closing brace, so the statement says nothing the brace below it does not. It reads as if something were being skipped — a reader has to look for the code it jumps over before concluding there is none — and when a statement is later appended to the method it lands after the return and never runs.
The following code illustrates the pattern detected by this rule:
static void xy_reset(int *counter) {
*counter = 0;
// FLAGGED: Redundant return at the end of a method
return;
}