always_declare_return_types
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:
main() { }
_bar() => _Foo();
class _Foo {
_foo() => 42;
}
GOOD:
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:
linter:
rules:
- always_declare_return_types
Unless stated otherwise, the documentation on this site reflects Dart 3.5.3. Page last updated on 2024-07-03. View source or report an issue.