Contents
Contents

Declare method return types.

This rule is available as of Dart 2.0.0.

This rule has a quick fix available.

Details

#

DO declare method return types.

When declaring a method or function always specify a return type. Declaring return types for functions helps improve your codebase by allowing the analyzer to more adequately check your code for errors that could occur during runtime.

BAD:

dart
main() { }

_bar() => _Foo();

class _Foo {
  _foo() => 42;
}

GOOD:

dart
void main() { }

_Foo _bar() => _Foo();

class _Foo {
  int _foo() => 42;
}

typedef predicate = bool Function(Object o);

Usage

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - always_declare_return_types