目录

always_declare_return_types

Declare method return types.

此规则自 Dart 2.0 版本起可用。

此规则提供 快速修复

详情

#

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);

使用方法

#

要启用 always_declare_return_types 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 always_declare_return_types

analysis_options.yaml
yaml
linter:
  rules:
    - always_declare_return_types