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
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
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;
}main() {} get answer => 42; typedef Handler(int x);class Foo { bar() => 1; bar() => 1; static make() => Foo(); static make() => Foo(); get size => 0; get size => 0; operator +(Foo other) => this;void outer() { inner() {}extension on int { doubled() => this * 2;Valid
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.
{
"linter": {
"rules": {
"style": {
"always-declare-return-types": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/always-declare-return-types: <reason>More style rules
- always-put-control-body-on-new-line
always_put_control_body_on_new_lineFlags a control-flow body that starts on the same line as its control clause.
- always-put-required-named-parameters-first
always_put_required_named_parameters_firstFlags a required named parameter declared after an optional named one.
- always-specify-types
always_specify_typesRequires explicit type annotations everywhere a type could be inferred.
- annotate-overrides
annotate_overridesrecommendedRequires
@overrideon members that override an inherited declaration. - arguments-ordering
Named arguments follow their resolved parameter declaration order by default.
- avoid-abbreviations-in-doc-comments
avoid_abbreviations_in_doc_commentsFlags Latin abbreviations in doc comments.
- avoid-annotating-with-dynamic
avoid_annotating_with_dynamicFlags parameters explicitly annotated with
dynamic. - avoid-bloc-public-fieldsbloc
Keep package-confirmed Bloc instance fields private; inherited API overrides are allowed.