always-declare-return-types

Same as always_declare_return_types in Dart lints

Group
Style
Path
lint/style/always-declare-return-types
Default
On (recommended)
Origin
Dart lints
Rule
3 of 512
recommended

Flags functions and methods declared without a return type.

Without an explicit return type, a function returns dynamic (or an inferred override type), which hides its contract from readers and callers. Top-level and local functions, getters, methods, operators, and legacy typedef F(...) aliases are checked. Setters and operator []= never declare a return type and are skipped, as are test_*/solo_test_* methods in a package-root test directory (reflective test runners). Operator diagnostics highlight only the operator name, not operator.

main() {}      // flagged
void main() {} // ok

Invalid

example.dartdart
main() {}

get answer => 42;

typedef Handler(int x);

class Foo {
  bar() => 1;
  static make() => Foo();
  get size => 0;
  operator +(Foo other) => this;
}

void outer() {
  inner() {}
  inner();
}

extension on int {
  doubled() => this * 2;
}
The function `main` should have a return type but doesn't.
1main() {}
The function `answer` should have a return type but doesn't.
2
3get answer => 42;
The function `Handler` should have a return type but doesn't.
4
5typedef Handler(int x);
The method `bar` should have a return type but doesn't.
7class Foo {
8 bar() => 1;
The method `make` should have a return type but doesn't.
8 bar() => 1;
9 static make() => Foo();
The method `size` should have a return type but doesn't.
9 static make() => Foo();
10 get size => 0;
The method `+` should have a return type but doesn't.
10 get size => 0;
11 operator +(Foo other) => this;
The function `inner` should have a return type but doesn't.
14void outer() {
15 inner() {}
The method `doubled` should have a return type but doesn't.
19extension on int {
20 doubled() => this * 2;

Valid

example.dartdart
void main() {}

int get answer => 42;

typedef void Handler(int x);

typedef Callback = Function(int);

set value(int v) {}

class Foo {
  int bar() => 1;
  static Foo make() => Foo();
  int get size => 0;
  set size(int v) {}
  Foo operator +(Foo other) => this;
  operator []=(int index, int value) {}
}

void outer() {
  void inner() {}
  inner();
  final f = () => 1;
  f();
}

Configure always-declare-return-types

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "always-declare-return-types": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/always-declare-return-types: <reason>