avoid-void-async
Same as avoid_void_async in Dart lints
- Group
- Style
- Path
lint/style/avoid-void-async- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 185 of 512
Avoid async functions and methods declared to return void.
Callers cannot await a void result, so they cannot know when the work has
finished or observe its errors. Return Future<void> instead:
void save() async {} // BAD
Future<void> save() async {} // GOOD
A top-level main and async* generators are exempt. Functions without a
written return type are skipped: an override may inherit void, which only
full type resolution can see.
Invalid
void save() async {}
void arrow() async => print('x');
class Store {
void flush() async {}
static void reset() async {}
void get refresh async {}
}
void outer() {
void inner() async {}
inner();
}
mixin Loader {
void load() async {}
}
void main() async {
void callback() async {}
[callback].forEach((run) => run());
}void save() async {} void arrow() async => print('x');class Store { void flush() async {} static void reset() async {} void get refresh async {}void outer() { void inner() async {}mixin Loader { void load() async {}void main() async { void callback() async {}Valid
import 'dart:async';
void main() async {}
Future<void> save() async {}
Future<int> compute() async => 1;
void syncWork() {}
Stream<void> events() async* {}
FutureOr<void> maybe() async {}
class Store {
Future<void> flush() async {}
void syncFlush() {}
Future<void> get refresh async {}
}
void outer() {
Future<void> inner() async {}
final callback = () async {};
inner();
callback();
}Configure avoid-void-async
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-void-async": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-void-async: <reason>More style rules
- avoid-wrapping-in-paddingflutter
Flags Padding directly wrapping a Flutter Container that can own the padding.
- binary-expression-operand-order
binary-expression-operand-orderFlags comparison expressions with a literal on the left-hand side.
- boolean-prefixes
boolean_prefixesFlags boolean identifiers that lack a conventional interrogative prefix.
- camel-case-extensions
camel_case_extensionsrecommendedFlags named extensions whose name is not
UpperCamelCase. - camel-case-types
camel_case_typesrecommendedFlags type names that are not
UpperCamelCase. - cast-nullable-to-non-nullable
cast_nullable_to_non_nullableFlags
e as Tcasts of a nullable value to a non-nullable type. - class-members-ordering
class_members_orderingFlags class members declared out of a canonical order.
- combinators-ordering
combinators_orderingFlags
show/hidecombinators whose names are not sorted alphabetically.