return_at_function_end
Reports a return; without a value as the last statement of a body, where the function ends anyway. Delete it.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- deletes the statement
What it reports
Section titled “What it reports”A return; without a value that is the last of several statements in the body of a function, method, constructor or function literal. The violation covers the statement.
It does not report a return;:
- that ends a block inside the body: an early exit;
- that is the only statement of the body: the function does nothing on purpose;
- after a statement that always leaves, which is the analyzer’s
dead_code. Some code,test_coreamong it, keeps tworeturn;in a row to stop dart2js from inlining a function.
The fix deletes the statement. It is not offered where a comment stands before the statement, or after it on its line.
The function ends there anyway.
Example
Section titled “Example”Violating
void greet(String name) { show(name); return;}Corrected
void greet(String name) { show(name);}Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: return_at_function_end// ignore_for_file: assay/return_at_function_end silences it in a whole file, and the prefixed // ignore: assay/return_at_function_end works too. See Suppressions.