From 69b52ba85b5610fc4d5c51b3ce5f72bea936f02a Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 18 Jun 2021 10:15:59 +0200 Subject: [PATCH] refactor: Move pedantic to dev_dependencies The unawaited method from the pedantic package was a historic solution for the case that you dont want to await a future in an async function. But now we can do this with just a comment which is the recommended way to do this now. This makes it possible to have pedantic as a dev_dependency which means just one dependency less. --- lib/encryption/encryption.dart | 26 +++++++++++++--------- lib/encryption/olm_manager.dart | 5 ++--- lib/encryption/utils/key_verification.dart | 12 +++++----- lib/src/client.dart | 12 +++++----- pubspec.yaml | 2 +- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 48d82dc5..8b48539c 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -19,7 +19,6 @@ import 'dart:convert'; import 'dart:async'; -import 'package:pedantic/pedantic.dart'; import 'package:olm/olm.dart' as olm; import '../matrix.dart'; @@ -106,26 +105,31 @@ class Encryption { .contains(event.type)) { // "just" room key request things. We don't need these asap, so we handle // them in the background - unawaited(runInRoot(() => keyManager.handleToDeviceEvent(event))); + // ignore: unawaited_futures + runInRoot(() => keyManager.handleToDeviceEvent(event)); } if (event.type == EventTypes.Dummy) { // the previous device just had to create a new olm session, due to olm session // corruption. We want to try to send it the last message we just sent it, if possible - unawaited(runInRoot(() => olmManager.handleToDeviceEvent(event))); + // ignore: unawaited_futures + runInRoot(() => olmManager.handleToDeviceEvent(event)); } if (event.type.startsWith('m.key.verification.')) { // some key verification event. No need to handle it now, we can easily // do this in the background - unawaited( - runInRoot(() => keyVerificationManager.handleToDeviceEvent(event))); + + // ignore: unawaited_futures + runInRoot(() => keyVerificationManager.handleToDeviceEvent(event)); } if (event.type.startsWith('m.secret.')) { // some ssss thing. We can do this in the background - unawaited(runInRoot(() => ssss.handleToDeviceEvent(event))); + // ignore: unawaited_futures + runInRoot(() => ssss.handleToDeviceEvent(event)); } if (event.sender == client.userID) { // maybe we need to re-try SSSS secrets - unawaited(runInRoot(() => ssss.periodicallyRequestMissingCache())); + // ignore: unawaited_futures + runInRoot(() => ssss.periodicallyRequestMissingCache()); } } @@ -139,14 +143,16 @@ class Encryption { update.content['content']['msgtype'] .startsWith('m.key.verification.'))) { // "just" key verification, no need to do this in sync - unawaited( - runInRoot(() => keyVerificationManager.handleEventUpdate(update))); + + // ignore: unawaited_futures + runInRoot(() => keyVerificationManager.handleEventUpdate(update)); } if (update.content['sender'] == client.userID && (!update.content.containsKey('unsigned') || !update.content['unsigned'].containsKey('transaction_id'))) { // maybe we need to re-try SSSS secrets - unawaited(runInRoot(() => ssss.periodicallyRequestMissingCache())); + // ignore: unawaited_futures + runInRoot(() => ssss.periodicallyRequestMissingCache()); } } diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 93dc3ad4..732553aa 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -21,7 +21,6 @@ import 'dart:convert'; import 'package:canonical_json/canonical_json.dart'; import 'package:matrix/matrix.dart'; import 'package:olm/olm.dart' as olm; -import 'package:pedantic/pedantic.dart'; import '../encryption/utils/json_signature_check_extension.dart'; import 'encryption.dart'; @@ -502,8 +501,8 @@ class OlmManager { } catch (_) { // okay, the thing errored while decrypting. It is safe to assume that the olm session is corrupt and we should generate a new one if (client.enableE2eeRecovery) { - unawaited( - runInRoot(() => restoreOlmSession(event.senderId, senderKey))); + // ignore: unawaited_futures + runInRoot(() => restoreOlmSession(event.senderId, senderKey)); } rethrow; } diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index ecdbc5a6..eab46153 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -21,7 +21,6 @@ import 'dart:typed_data'; import 'package:canonical_json/canonical_json.dart'; import 'package:olm/olm.dart' as olm; -import 'package:pedantic/pedantic.dart'; import '../../matrix.dart'; import '../encryption.dart'; @@ -457,8 +456,9 @@ class KeyVerification { // no need to request cache, we already have it return; } - unawaited(encryption.ssss - .maybeRequestAll(_verifiedDevices.whereType().toList())); + // ignore: unawaited_futures + encryption.ssss + .maybeRequestAll(_verifiedDevices.whereType().toList()); if (requestInterval.length <= i) { return; } @@ -500,7 +500,8 @@ class KeyVerification { if (verifiedMasterKey && userId == client.userID) { // it was our own master key, let's request the cross signing keys // we do it in the background, thus no await needed here - unawaited(maybeRequestSSSSSecrets()); + // ignore: unawaited_futures + maybeRequestSSSSSecrets(); } await send(EventTypes.KeyVerificationDone, {}); @@ -510,7 +511,8 @@ class KeyVerification { // these keys can be signed! Let's do so if (await encryption.crossSigning.isCached()) { // and now let's sign them all in the background - unawaited(encryption.crossSigning.sign(_verifiedDevices)); + // ignore: unawaited_futures + encryption.crossSigning.sign(_verifiedDevices); } else if (!wasUnknownSession) { askingSSSS = true; } diff --git a/lib/src/client.dart b/lib/src/client.dart index ea49968e..43d511f7 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -24,7 +24,6 @@ import 'dart:typed_data'; import 'package:matrix/src/utils/run_in_root.dart'; import 'package:http/http.dart' as http; import 'package:olm/olm.dart' as olm; -import 'package:pedantic/pedantic.dart'; import '../encryption.dart'; import '../matrix.dart'; @@ -677,7 +676,8 @@ class Client extends MatrixApi { await super.setTyping(userId, roomId, typing, timeout: timeout); final room = getRoomById(roomId); if (typing && room != null && encryptionEnabled && room.encrypted) { - unawaited(encryption.keyManager.prepareOutboundGroupSession(roomId)); + // ignore: unawaited_futures + encryption.keyManager.prepareOutboundGroupSession(roomId); } } @@ -1890,7 +1890,8 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); } // now send out the background chunks if (i < deviceKeys.length) { - unawaited(() async { + // ignore: unawaited_futures + () async { for (; i < deviceKeys.length; i += chunkSize) { // wait 50ms to not freeze the UI await Future.delayed(Duration(milliseconds: 50)); @@ -1901,9 +1902,10 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); ? deviceKeys.length : i + chunkSize); // and send - unawaited(sendToDeviceEncrypted(chunk, eventType, message)); + // ignore: unawaited_futures + sendToDeviceEncrypted(chunk, eventType, message); } - }()); + }(); } } diff --git a/pubspec.yaml b/pubspec.yaml index a4bb82df..8ca7a113 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,11 +20,11 @@ dependencies: isolate: ^2.0.3 matrix_api_lite: ^0.3.3 hive: ^2.0.4 - pedantic: ^1.11.0 ffi: ^1.0.0 js: ^0.6.3 dev_dependencies: + pedantic: ^1.11.0 test: ^1.15.7 coverage: ">=0.15.0 <2.0.0" moor_generator: ^4.0.0