prefer_immediate_return

SeverityQuick FixOptions
Info

Details

DO return the result of an expression directly instead of assigning it to a variable and then returning the variable.

Bad
int add(int a, int b) {
  final result = a + b;
  return result;
}
Good
int add(int a, int b) {
  return a + b;
}

Usage

To enable the prefer_immediate_return rule, add prefer_immediate_return under custom_lint > rules in your analysis_options.yaml file:

custom_lint:
  rules:
    - prefer_immediate_return