prefer-expect-later
- Group
- Correctness
- Path
lint/correctness/prefer-expect-later- Default
- Off, opt in
- Origin
- Falcon
- Domain
- test
- Rule
- 351 of 512
Requires expectLater when a canonical expect call receives an unawaited Future.
Invalid
import 'package:test/test.dart' as t;
Future<int> number() async => 1;
void main() {
t.test('unawaited future actuals', () {
t.expect(Future.value(1), 1);
t.expect(Future.value(1), t.completes);
t.expect(Future.error('bad'), t.throwsA(t.equals('bad')));
t.expect(number(), t.equals(1));
final pending = Future.value(1);
t.expect(pending, t.equals(1));
t.expect(Future.value(1), t.predicate((value) => true));
});
} t.test('unawaited future actuals', () { t.expect(Future.value(1), 1); t.expect(Future.value(1), 1); t.expect(Future.value(1), t.completes); t.expect(Future.value(1), t.completes); t.expect(Future.error('bad'), t.throwsA(t.equals('bad'))); t.expect(Future.error('bad'), t.throwsA(t.equals('bad'))); t.expect(number(), t.equals(1)); final pending = Future.value(1); t.expect(pending, t.equals(1)); t.expect(pending, t.equals(1)); t.expect(Future.value(1), t.predicate((value) => true));Valid
import 'package:test/test.dart' as t;
void main() {
t.test('good', () async {
await t.expectLater(Future.value(1), t.completes);
await t.expectLater(Stream.value(1), t.emits(1));
t.expect(1, t.equals(1));
t.expect(true, t.isTrue);
t.expect(null, t.isNull);
final completes = 1;
t.expect(1, completes);
void expect(dynamic value, dynamic matcher) {}
expect(Future.value(1), t.completes);
});
}Configure prefer-expect-later
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"prefer-expect-later": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/prefer-expect-later: <reason>More correctness rules
- prefer-immutable-bloc-eventsrecommendedbloc
Flags Bloc event classes without an explicit @immutable annotation.
- prefer-immutable-bloc-staterecommendedbloc
Flags Bloc state classes without an explicit @immutable annotation.
- prefer-immutable-provider-argumentsriverpod
Requires stable value equality for freshly created Riverpod family keys.
- prefer-read-for-methodsrecommendedprovider
Flags void method actions on a listening Provider lookup during build.
- prefer-ref-read-for-methodsrecommendedriverpod
Flags watching a Riverpod notifier solely to invoke one of its methods.
- prefer-relative-imports
prefer_relative_importsPrefer relative imports for libraries of the same package under
lib/. - prefer-sealed-bloc-eventsrecommendedbloc
Flags Bloc event classes without a sealed or final modifier.
- prefer-sealed-bloc-staterecommendedbloc
Flags Bloc state classes without a sealed or final modifier.