always_declare_return_types
Declare method return types.
This rule is available as of Dart 2.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
除非另有说明,文档之所提及适用于 Dart 3.6.0 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。