Skip to content

Commit a9031aa

Browse files
committed
lint: Enable unawaited_futures
This also fixes linting issues on the remaining affected tests. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 2a67aae commit a9031aa

10 files changed

+93
-87
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ linter:
2525
no_literal_bool_comparisons: true
2626
prefer_relative_imports: true
2727
unnecessary_statements: true
28+
unawaited_futures: true

test/api/core_test.dart

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ void main() {
3434
});
3535
}
3636

37-
checkRequest(null, '/api/v1/example/route');
38-
checkRequest({}, '/api/v1/example/route?');
39-
checkRequest({'x': 3}, '/api/v1/example/route?x=3');
40-
checkRequest({'x': 3, 'y': 4}, '/api/v1/example/route?x=3&y=4');
41-
checkRequest({'x': null}, '/api/v1/example/route?x=null');
42-
checkRequest({'x': true}, '/api/v1/example/route?x=true');
43-
checkRequest({'x': 'foo'}, '/api/v1/example/route?x=%22foo%22');
44-
checkRequest({'x': [1, 2]}, '/api/v1/example/route?x=%5B1%2C2%5D');
45-
checkRequest({'x': {'y': 1}}, '/api/v1/example/route?x=%7B%22y%22%3A1%7D');
46-
checkRequest({'x': RawParameter('foo')},
37+
await checkRequest(null, '/api/v1/example/route');
38+
await checkRequest({}, '/api/v1/example/route?');
39+
await checkRequest({'x': 3}, '/api/v1/example/route?x=3');
40+
await checkRequest({'x': 3, 'y': 4}, '/api/v1/example/route?x=3&y=4');
41+
await checkRequest({'x': null}, '/api/v1/example/route?x=null');
42+
await checkRequest({'x': true}, '/api/v1/example/route?x=true');
43+
await checkRequest({'x': 'foo'}, '/api/v1/example/route?x=%22foo%22');
44+
await checkRequest({'x': [1, 2]}, '/api/v1/example/route?x=%5B1%2C2%5D');
45+
await checkRequest({'x': {'y': 1}}, '/api/v1/example/route?x=%7B%22y%22%3A1%7D');
46+
await checkRequest({'x': RawParameter('foo')},
4747
'/api/v1/example/route?x=foo');
48-
checkRequest({'x': RawParameter('foo'), 'y': 'bar'},
48+
await checkRequest({'x': RawParameter('foo'), 'y': 'bar'},
4949
'/api/v1/example/route?x=foo&y=%22bar%22');
5050
});
5151

@@ -67,17 +67,17 @@ void main() {
6767
});
6868
}
6969

70-
checkRequest(null, '', expectContentType: false);
71-
checkRequest({}, '');
72-
checkRequest({'x': 3}, 'x=3');
73-
checkRequest({'x': 3, 'y': 4}, 'x=3&y=4');
74-
checkRequest({'x': null}, 'x=null');
75-
checkRequest({'x': true}, 'x=true');
76-
checkRequest({'x': 'foo'}, 'x=%22foo%22');
77-
checkRequest({'x': [1, 2]}, 'x=%5B1%2C2%5D');
78-
checkRequest({'x': {'y': 1}}, 'x=%7B%22y%22%3A1%7D');
79-
checkRequest({'x': RawParameter('foo')}, 'x=foo');
80-
checkRequest({'x': RawParameter('foo'), 'y': 'bar'}, 'x=foo&y=%22bar%22');
70+
await checkRequest(null, '', expectContentType: false);
71+
await checkRequest({}, '');
72+
await checkRequest({'x': 3}, 'x=3');
73+
await checkRequest({'x': 3, 'y': 4}, 'x=3&y=4');
74+
await checkRequest({'x': null}, 'x=null');
75+
await checkRequest({'x': true}, 'x=true');
76+
await checkRequest({'x': 'foo'}, 'x=%22foo%22');
77+
await checkRequest({'x': [1, 2]}, 'x=%5B1%2C2%5D');
78+
await checkRequest({'x': {'y': 1}}, 'x=%7B%22y%22%3A1%7D');
79+
await checkRequest({'x': RawParameter('foo')}, 'x=foo');
80+
await checkRequest({'x': RawParameter('foo'), 'y': 'bar'}, 'x=foo&y=%22bar%22');
8181
});
8282

8383
test('ApiConnection.postFileFromStream', () async {
@@ -111,18 +111,18 @@ void main() {
111111
});
112112
}
113113

114-
checkRequest([], 0, filename: null);
115-
checkRequest(['asdf'.codeUnits], 4, filename: null);
116-
checkRequest(['asd'.codeUnits, 'f'.codeUnits], 4, filename: null);
114+
await checkRequest([], 0, filename: null);
115+
await checkRequest(['asdf'.codeUnits], 4, filename: null);
116+
await checkRequest(['asd'.codeUnits, 'f'.codeUnits], 4, filename: null);
117117

118-
checkRequest(['asdf'.codeUnits], 4, filename: 'info.txt');
119-
checkRequest(['asdf'.codeUnits], 4,
118+
await checkRequest(['asdf'.codeUnits], 4, filename: 'info.txt');
119+
await checkRequest(['asdf'.codeUnits], 4,
120120
filename: 'image.jpg', contentType: 'image/jpeg');
121-
checkRequest(['asdf'.codeUnits], 4,
121+
await checkRequest(['asdf'.codeUnits], 4,
122122
filename: 'image.jpg', contentType: 'asdfjkl;', isContentTypeInvalid: true);
123123

124-
checkRequest(['asdf'.codeUnits], 1, filename: null); // nothing on client side catches a wrong length
125-
checkRequest(['asdf'.codeUnits], 100, filename: null);
124+
await checkRequest(['asdf'.codeUnits], 1, filename: null); // nothing on client side catches a wrong length
125+
await checkRequest(['asdf'.codeUnits], 100, filename: null);
126126
});
127127

128128
test('ApiConnection.delete', () async {
@@ -143,17 +143,17 @@ void main() {
143143
});
144144
}
145145

146-
checkRequest(null, '', expectContentType: false);
147-
checkRequest({}, '');
148-
checkRequest({'x': 3}, 'x=3');
149-
checkRequest({'x': 3, 'y': 4}, 'x=3&y=4');
150-
checkRequest({'x': null}, 'x=null');
151-
checkRequest({'x': true}, 'x=true');
152-
checkRequest({'x': 'foo'}, 'x=%22foo%22');
153-
checkRequest({'x': [1, 2]}, 'x=%5B1%2C2%5D');
154-
checkRequest({'x': {'y': 1}}, 'x=%7B%22y%22%3A1%7D');
155-
checkRequest({'x': RawParameter('foo')}, 'x=foo');
156-
checkRequest({'x': RawParameter('foo'), 'y': 'bar'}, 'x=foo&y=%22bar%22');
146+
await checkRequest(null, '', expectContentType: false);
147+
await checkRequest({}, '');
148+
await checkRequest({'x': 3}, 'x=3');
149+
await checkRequest({'x': 3, 'y': 4}, 'x=3&y=4');
150+
await checkRequest({'x': null}, 'x=null');
151+
await checkRequest({'x': true}, 'x=true');
152+
await checkRequest({'x': 'foo'}, 'x=%22foo%22');
153+
await checkRequest({'x': [1, 2]}, 'x=%5B1%2C2%5D');
154+
await checkRequest({'x': {'y': 1}}, 'x=%7B%22y%22%3A1%7D');
155+
await checkRequest({'x': RawParameter('foo')}, 'x=foo');
156+
await checkRequest({'x': RawParameter('foo'), 'y': 'bar'}, 'x=foo&y=%22bar%22');
157157
});
158158

159159
test('API success result', () async {
@@ -176,13 +176,13 @@ void main() {
176176
}
177177

178178
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
179-
checkRequest(http.ClientException('Oops'), (it) => it
179+
await checkRequest(http.ClientException('Oops'), (it) => it
180180
..message.equals('Oops')
181181
..asString.equals('NetworkException: Oops (ClientException: Oops)'));
182-
checkRequest(const TlsException('Oops'), (it) => it
182+
await checkRequest(const TlsException('Oops'), (it) => it
183183
..message.equals('Oops')
184184
..asString.equals('NetworkException: Oops (TlsException: Oops)'));
185-
checkRequest((foo: 'bar'), (it) => it
185+
await checkRequest((foo: 'bar'), (it) => it
186186
..message.equals(zulipLocalizations.errorNetworkRequestFailed)
187187
..asString.equals('NetworkException: Network request failed ((foo: bar))'));
188188
});
@@ -233,17 +233,17 @@ void main() {
233233
tryRequest(json: { 'result': 'error', 'code': 'ERR', 'msg': 'Oops'}, httpStatus: 400),
234234
).throws<ZulipApiException>();
235235

236-
checkMalformed(json: {'result': 'success', 'code': 'ERR', 'msg': 'Oops'});
237-
checkMalformed(json: {'result': 'nonsense', 'code': 'ERR', 'msg': 'Oops'});
238-
checkMalformed(json: {/* result */ 'code': 'ERR', 'msg': 'Oops'});
239-
checkMalformed(json: {'result': 'error', 'code': 1, 'msg': 'Oops'});
240-
checkMalformed(json: {'result': 'error', 'code': 'ERR' /* msg */ });
241-
checkMalformed(json: {'result': 'error', 'code': 'ERR', 'msg': 1 });
242-
checkMalformed(json: {});
243-
checkMalformed(body: '');
244-
checkMalformed(body: '<html><body><p>An error occurred</p></body></html>');
245-
checkMalformed(json: {'result': 'nonsense'}, httpStatus: 401);
246-
checkMalformed(json: {'result': 'nonsense'}, httpStatus: 499);
236+
await checkMalformed(json: {'result': 'success', 'code': 'ERR', 'msg': 'Oops'});
237+
await checkMalformed(json: {'result': 'nonsense', 'code': 'ERR', 'msg': 'Oops'});
238+
await checkMalformed(json: {/* result */ 'code': 'ERR', 'msg': 'Oops'});
239+
await checkMalformed(json: {'result': 'error', 'code': 1, 'msg': 'Oops'});
240+
await checkMalformed(json: {'result': 'error', 'code': 'ERR' /* msg */ });
241+
await checkMalformed(json: {'result': 'error', 'code': 'ERR', 'msg': 1 });
242+
await checkMalformed(json: {});
243+
await checkMalformed(body: '');
244+
await checkMalformed(body: '<html><body><p>An error occurred</p></body></html>');
245+
await checkMalformed(json: {'result': 'nonsense'}, httpStatus: 401);
246+
await checkMalformed(json: {'result': 'nonsense'}, httpStatus: 499);
247247
});
248248

249249
test('API 5xx errors', () async {

test/api/fake_api_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:checks/checks.dart';
24
import 'package:test/scaffolding.dart';
35
import 'package:zulip/api/exception.dart';
@@ -29,8 +31,8 @@ void main() {
2931
json: {'a': 3});
3032

3133
Map<String, dynamic>? result;
32-
connection.get('aRoute', (json) => json, '/', null)
33-
.then((r) { result = r; });
34+
unawaited(connection.get('aRoute', (json) => json, '/', null)
35+
.then((r) { result = r; }));
3436

3537
async.elapse(const Duration(seconds: 1));
3638
check(result).isNull();
@@ -45,8 +47,8 @@ void main() {
4547
exception: Exception("oops"));
4648

4749
Object? error;
48-
connection.get('aRoute', (json) => null, '/', null)
49-
.catchError((Object e) { error = e; });
50+
unawaited(connection.get('aRoute', (json) => null, '/', null)
51+
.catchError((Object e) { error = e; }));
5052

5153
async.elapse(const Duration(seconds: 1));
5254
check(error).isNull();

test/model/channel_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ void main() {
264264
await store.addSubscription(
265265
eg.subscription(stream1, isMuted: streamMuted));
266266
}
267-
store.handleEvent(mkEvent(oldPolicy));
267+
await store.handleEvent(mkEvent(oldPolicy));
268268
final oldVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, 'topic');
269269
final oldVisible = store.isTopicVisible(stream1.streamId, 'topic');
270270

271271
final event = mkEvent(newPolicy);
272272
final willChangeInStream = store.willChangeIfTopicVisibleInStream(event);
273273
final willChange = store.willChangeIfTopicVisible(event);
274274

275-
store.handleEvent(event);
275+
await store.handleEvent(event);
276276
final newVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, 'topic');
277277
final newVisible = store.isTopicVisible(stream1.streamId, 'topic');
278278

test/model/store_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ void main() {
151151

152152
test('reject changing id, realmUrl, or userId', () async {
153153
final globalStore = eg.globalStore(accounts: [eg.selfAccount]);
154-
check(globalStore.updateAccount(eg.selfAccount.id, const AccountsCompanion(
154+
await check(globalStore.updateAccount(eg.selfAccount.id, const AccountsCompanion(
155155
id: Value(1234)))).throws();
156-
check(globalStore.updateAccount(eg.selfAccount.id, AccountsCompanion(
156+
await check(globalStore.updateAccount(eg.selfAccount.id, AccountsCompanion(
157157
realmUrl: Value(Uri.parse('https://other.example'))))).throws();
158-
check(globalStore.updateAccount(eg.selfAccount.id, const AccountsCompanion(
158+
await check(globalStore.updateAccount(eg.selfAccount.id, const AccountsCompanion(
159159
userId: Value(1234)))).throws();
160160
});
161161

@@ -289,7 +289,7 @@ void main() {
289289
connection.prepare(exception: Exception('failed'));
290290
final future = UpdateMachine.load(globalStore, eg.selfAccount.id);
291291
bool complete = false;
292-
future.whenComplete(() => complete = true);
292+
unawaited(future.whenComplete(() => complete = true));
293293
async.flushMicrotasks();
294294
checkLastRequest();
295295
check(complete).isFalse();

test/notifications/display_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,14 @@ void main() {
590590
]);
591591

592592
// A RemoveFcmMessage for the first two messages; the notification stays.
593-
receiveFcmMessage(async, removeFcmMessage([message1, message2]));
593+
await receiveFcmMessage(async, removeFcmMessage([message1, message2]));
594594
check(testBinding.androidNotificationHost.activeNotifications).deepEquals(<Condition<Object?>>[
595595
conditionActiveNotif(data3, 'stream:${stream.streamId}:$topicA'),
596596
conditionSummaryActiveNotif(expectedGroupKey),
597597
]);
598598

599599
// Then a RemoveFcmMessage for the last message; clear the notification.
600-
receiveFcmMessage(async, removeFcmMessage([message3]));
600+
await receiveFcmMessage(async, removeFcmMessage([message3]));
601601
check(testBinding.androidNotificationHost.activeNotifications).isEmpty();
602602
})));
603603

@@ -782,14 +782,14 @@ void main() {
782782

783783
testWidgets('stream message', (tester) async {
784784
addTearDown(testBinding.reset);
785-
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
785+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
786786
await prepare(tester);
787787
await checkOpenNotification(tester, eg.selfAccount, eg.streamMessage());
788788
});
789789

790790
testWidgets('direct message', (tester) async {
791791
addTearDown(testBinding.reset);
792-
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
792+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
793793
await prepare(tester);
794794
await checkOpenNotification(tester, eg.selfAccount,
795795
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
@@ -803,7 +803,7 @@ void main() {
803803

804804
testWidgets('mismatching account', (tester) async {
805805
addTearDown(testBinding.reset);
806-
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
806+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
807807
await prepare(tester);
808808
await openNotification(tester, eg.otherAccount, eg.streamMessage());
809809
check(pushedRoutes).isEmpty();
@@ -822,7 +822,7 @@ void main() {
822822
eg.account(id: 1004, realmUrl: realmUrlB, user: user2),
823823
];
824824
for (final account in accounts) {
825-
testBinding.globalStore.add(account, eg.initialSnapshot());
825+
await testBinding.globalStore.add(account, eg.initialSnapshot());
826826
}
827827
await prepare(tester);
828828

@@ -834,7 +834,7 @@ void main() {
834834

835835
testWidgets('wait for app to become ready', (tester) async {
836836
addTearDown(testBinding.reset);
837-
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
837+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
838838
await prepare(tester, early: true);
839839
final message = eg.streamMessage();
840840
await openNotification(tester, eg.selfAccount, message);
@@ -864,7 +864,7 @@ void main() {
864864
NotificationAppLaunchDetails(true, notificationResponse: response);
865865

866866
// Now start the app.
867-
testBinding.globalStore.add(account, eg.initialSnapshot());
867+
await testBinding.globalStore.add(account, eg.initialSnapshot());
868868
await prepare(tester, early: true);
869869
check(pushedRoutes).isEmpty(); // GlobalStore hasn't loaded yet
870870

test/widgets/actions_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23

34
import 'package:checks/checks.dart';
@@ -52,7 +53,7 @@ void main() {
5253
processedCount: 11, updatedCount: 3,
5354
firstProcessedId: null, lastProcessedId: null,
5455
foundOldest: true, foundNewest: true).toJson());
55-
markNarrowAsRead(context, narrow);
56+
unawaited(markNarrowAsRead(context, narrow));
5657
await tester.pump(Duration.zero);
5758
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIs(IsOperand.unread));
5859
check(connection.lastRequest).isA<http.Request>()
@@ -76,7 +77,7 @@ void main() {
7677
processedCount: 11, updatedCount: 3,
7778
firstProcessedId: null, lastProcessedId: null,
7879
foundOldest: true, foundNewest: true).toJson());
79-
markNarrowAsRead(context, narrow);
80+
unawaited(markNarrowAsRead(context, narrow));
8081
await tester.pump(Duration.zero);
8182
check(connection.lastRequest).isA<http.Request>()
8283
..method.equals('POST')
@@ -101,7 +102,7 @@ void main() {
101102
processedCount: 11, updatedCount: 3,
102103
firstProcessedId: null, lastProcessedId: null,
103104
foundOldest: true, foundNewest: true).toJson());
104-
markNarrowAsRead(context, narrow);
105+
unawaited(markNarrowAsRead(context, narrow));
105106
await tester.pump(Duration.zero);
106107
await tester.pumpAndSettle();
107108
check(store.unreads.oldUnreadsMissing).isFalse();
@@ -115,7 +116,7 @@ void main() {
115116

116117
connection.zulipFeatureLevel = 154;
117118
connection.prepare(json: {});
118-
markNarrowAsRead(context, narrow);
119+
unawaited(markNarrowAsRead(context, narrow));
119120
await tester.pump(Duration.zero);
120121
check(connection.lastRequest).isA<http.Request>()
121122
..method.equals('POST')
@@ -133,7 +134,7 @@ void main() {
133134
await prepare(tester);
134135
connection.zulipFeatureLevel = 154;
135136
connection.prepare(json: {});
136-
markNarrowAsRead(context, narrow);
137+
unawaited(markNarrowAsRead(context, narrow));
137138
await tester.pump(Duration.zero);
138139
check(connection.lastRequest).isA<http.Request>()
139140
..method.equals('POST')
@@ -148,7 +149,7 @@ void main() {
148149
await prepare(tester);
149150
connection.zulipFeatureLevel = 154;
150151
connection.prepare(json: {});
151-
markNarrowAsRead(context, narrow);
152+
unawaited(markNarrowAsRead(context, narrow));
152153
await tester.pump(Duration.zero);
153154
check(connection.lastRequest).isA<http.Request>()
154155
..method.equals('POST')
@@ -170,7 +171,7 @@ void main() {
170171
connection.zulipFeatureLevel = 154;
171172
connection.prepare(json:
172173
UpdateMessageFlagsResult(messages: [message.id]).toJson());
173-
markNarrowAsRead(context, narrow);
174+
unawaited(markNarrowAsRead(context, narrow));
174175
await tester.pump(Duration.zero);
175176
check(connection.lastRequest).isA<http.Request>()
176177
..method.equals('POST')
@@ -190,7 +191,7 @@ void main() {
190191
connection.zulipFeatureLevel = 154;
191192
connection.prepare(json:
192193
UpdateMessageFlagsResult(messages: [message.id]).toJson());
193-
markNarrowAsRead(context, narrow);
194+
unawaited(markNarrowAsRead(context, narrow));
194195
await tester.pump(Duration.zero);
195196
check(connection.lastRequest).isA<http.Request>()
196197
..method.equals('POST')

test/widgets/inbox_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void main() {
485485
.equals(ChannelColorSwatch.light(initialColor).barBackground);
486486

487487
final newColor = Colors.orange.argbInt;
488-
store.handleEvent(SubscriptionUpdateEvent(id: 1, streamId: 1,
488+
await store.handleEvent(SubscriptionUpdateEvent(id: 1, streamId: 1,
489489
property: SubscriptionProperty.color, value: newColor));
490490
await tester.pump();
491491

0 commit comments

Comments
 (0)