avoid-unnecessary-futures
preset: recommended
Warns when a return type of a declaration is unnecessary wrapped into a Future
.
Functions that return Future
have an unfortunate side-effect: they also tend to mark outer functions as async
(since you usually need to use await
). Removing unnecessary futures can help reduce the number of async functions and methods.
Example
❌ Bad:
// LINT: Unnecessary 'Future' return type. Try rewriting the function to be a sync function instead.
Future<String> asyncValue() async => 'value';
class SomeClass {
// LINT: Unnecessary 'Future' return type. Try rewriting the function to be a sync function instead.
Future<int> asyncMethod() async => 1;
}
✅ Good:
String value() => 'value'; // Correct, just 'String'
class SomeClass {
int method() => 1;
}