From 44ca96e544e1c7b43099f2ffebb64225670252bf Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Tue, 9 Mar 2021 17:28:04 +0000 Subject: [PATCH] refactor: Update pedantic This enforces to NOT use curly braces in Strings where not needed and not await non-future variables. --- .gitlab-ci.yml | 4 ++-- lib/encryption/olm_manager.dart | 2 +- lib/encryption/ssss.dart | 8 ++++---- lib/encryption/utils/key_verification.dart | 16 ++++++++-------- lib/src/client.dart | 8 ++++---- lib/src/database/database.dart | 4 ++-- lib/src/utils/device_keys_list.dart | 13 +++++++------ lib/src/utils/markdown.dart | 4 ++-- pubspec.yaml | 3 +-- test/client_test.dart | 6 +++--- .../encrypt_decrypt_to_device_test.dart | 2 +- test/encryption/key_verification_test.dart | 2 +- test/encryption/ssss_test.dart | 8 ++++---- test/fake_client.dart | 2 +- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da28c8de..2381f6b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,8 +24,8 @@ coverage: - chmod +x ./prepare.sh - chmod +x ./test.sh - rm -r example - - su -c ./prepare.sh test - - su -c ./test.sh test + - ./prepare.sh test + - ./test.sh test artifacts: paths: - coverage/ diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 11ee8e85..529e7587 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -541,7 +541,7 @@ class OlmManager { if (!deviceKey.checkJsonSignature(fingerprintKey, userId, deviceId)) { continue; } - Logs().v('[OlmManager] Starting session with ${userId}:${deviceId}'); + Logs().v('[OlmManager] Starting session with $userId:$deviceId'); var session = olm.Session(); try { session.create_outbound(_olmAccount, identityKey, deviceKey['key']); diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 98c27a03..debce826 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -401,7 +401,7 @@ class SSSS { Future request(String type, [List devices]) async { // only send to own, verified devices - Logs().i('[SSSS] Requesting type ${type}...'); + Logs().i('[SSSS] Requesting type $type...'); if (devices == null || devices.isEmpty) { if (!client.userDeviceKeys.containsKey(client.userID)) { Logs().w('[SSSS] User does not have any devices'); @@ -477,12 +477,12 @@ class SSSS { final type = event.content['name']; final secret = await getCached(type); if (secret == null) { - Logs().i( - '[SSSS] We don\'t have the secret for ${type} ourself, ignoring'); + Logs() + .i('[SSSS] We don\'t have the secret for $type ourself, ignoring'); return; // seems like we don't have this, either } // okay, all checks out...time to share this secret! - Logs().i('[SSSS] Replying with secret for ${type}'); + Logs().i('[SSSS] Replying with secret for $type'); await client.sendToDeviceEncrypted( [device], EventTypes.SecretSend, diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index 2089ee63..06d935eb 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -208,7 +208,7 @@ class KeyVerification { await Future.delayed(Duration(milliseconds: 50)); } _handlePayloadLock = true; - Logs().i('[Key Verification] Received type ${type}: ' + payload.toString()); + Logs().i('[Key Verification] Received type $type: ' + payload.toString()); try { var thisLastStep = lastStep; switch (type) { @@ -277,7 +277,7 @@ class KeyVerification { if (payload['method'] == method.type) { // same method. Determine priority final ourEntry = '${client.userID}|${client.deviceID}'; - final entries = [ourEntry, '${userId}|${deviceId}']; + final entries = [ourEntry, '$userId|$deviceId']; entries.sort(); if (entries.first == ourEntry) { // our start won, nothing to do @@ -584,14 +584,14 @@ class KeyVerification { Future send(String type, Map payload) async { makePayload(payload); - Logs().i('[Key Verification] Sending type ${type}: ' + payload.toString()); + Logs().i('[Key Verification] Sending type $type: ' + payload.toString()); if (room != null) { - Logs().i('[Key Verification] Sending to ${userId} in room ${room.id}...'); + Logs().i('[Key Verification] Sending to $userId in room ${room.id}...'); if ({EventTypes.KeyVerificationRequest}.contains(type)) { payload['msgtype'] = type; payload['to'] = userId; payload['body'] = - 'Attempting verification request. (${type}) Apparently your client doesn\'t support this'; + 'Attempting verification request. ($type) Apparently your client doesn\'t support this'; type = EventTypes.Message; } final newTransactionId = await room.sendEvent(payload, type: type); @@ -600,7 +600,7 @@ class KeyVerification { encryption.keyVerificationManager.addRequest(this); } } else { - Logs().i('[Key Verification] Sending to ${userId} device ${deviceId}...'); + Logs().i('[Key Verification] Sending to $userId device $deviceId...'); if (deviceId == '*') { if ({ EventTypes.KeyVerificationRequest, @@ -609,7 +609,7 @@ class KeyVerification { await client.sendToDevicesOfUserIds({userId}, type, payload); } else { Logs().e( - '[Key Verification] Tried to broadcast and un-broadcastable type: ${type}'); + '[Key Verification] Tried to broadcast and un-broadcastable type: $type'); } } else { await client.sendToDeviceEncrypted( @@ -873,7 +873,7 @@ class _KeyVerificationMethodSas extends _KeyVerificationMethod { final ourInfo = '${client.userID}|${client.deviceID}|${sas.get_pubkey()}|'; final theirInfo = - '${request.userId}|${request.deviceId}|${theirPublicKey}|'; + '${request.userId}|${request.deviceId}|$theirPublicKey|'; sasInfo = 'MATRIX_KEY_VERIFICATION_SAS|' + (request.startedVerification ? ourInfo + theirInfo diff --git a/lib/src/client.dart b/lib/src/client.dart index 823dd34e..57e1214d 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -223,7 +223,7 @@ class Client extends MatrixApi { String generateUniqueTransactionId() { _transactionCounter++; - return '${clientName}-${_transactionCounter}-${DateTime.now().millisecondsSinceEpoch}'; + return '$clientName-$_transactionCounter-${DateTime.now().millisecondsSinceEpoch}'; } Room getRoomByAlias(String alias) { @@ -459,7 +459,7 @@ class Client extends MatrixApi { Logs().e('Logout failed', e, s); rethrow; } finally { - await clear(); + clear(); } } @@ -473,7 +473,7 @@ class Client extends MatrixApi { Logs().e('Logout all failed', e, s); rethrow; } finally { - await clear(); + clear(); } } @@ -770,7 +770,7 @@ class Client extends MatrixApi { /// If one of [newToken], [newUserID], [newDeviceID], [newDeviceName] is set then /// all of them must be set! If you don't set them, this method will try to /// get them from the database. - void init({ + Future init({ String newToken, Uri newHomeserver, String newUserID, diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index 0a5b004e..21cde8a0 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -385,7 +385,7 @@ class Database extends _$Database { final Set _ensuredRooms = {}; Future storeRoomUpdate(int clientId, sdk.RoomUpdate roomUpdate, [sdk.Room oldRoom]) async { - final setKey = '${clientId};${roomUpdate.id}'; + final setKey = '$clientId;${roomUpdate.id}'; if (roomUpdate.membership != api.Membership.leave) { if (!_ensuredRooms.contains(setKey)) { await ensureRoomExists(clientId, roomUpdate.id, @@ -620,7 +620,7 @@ class Database extends _$Database { } Future forgetRoom(int clientId, String roomId) async { - final setKey = '${clientId};${roomId}'; + final setKey = '$clientId;$roomId'; _ensuredRooms.remove(setKey); await (delete(rooms) ..where((r) => r.roomId.equals(roomId) & r.clientId.equals(clientId))) diff --git a/lib/src/utils/device_keys_list.dart b/lib/src/utils/device_keys_list.dart index 0daccfce..3b59c65b 100644 --- a/lib/src/utils/device_keys_list.dart +++ b/lib/src/utils/device_keys_list.dart @@ -215,7 +215,7 @@ abstract class SignableKey extends MatrixSignableKey { } visited ??= {}; onlyValidateUserIds ??= {}; - final setKey = '${userId};${identifier}'; + final setKey = '$userId;$identifier'; if (visited.contains(setKey) || (onlyValidateUserIds.isNotEmpty && !onlyValidateUserIds.contains(userId))) { @@ -310,13 +310,14 @@ abstract class SignableKey extends MatrixSignableKey { return false; } - void setVerified(bool newVerified, [bool sign = true]) { + Future setVerified(bool newVerified, [bool sign = true]) async { _verified = newVerified; if (newVerified && sign && client.encryptionEnabled && client.encryption.crossSigning.signable([this])) { // sign the key! + // ignore: unawaited_futures client.encryption.crossSigning.sign([this]); } } @@ -344,8 +345,8 @@ class CrossSigningKey extends SignableKey { userId != null && publicKey != null && keys != null && ed25519Key != null; @override - Future setVerified(bool newVerified, [bool sign = true]) { - super.setVerified(newVerified, sign); + Future setVerified(bool newVerified, [bool sign = true]) async { + await super.setVerified(newVerified, sign); return client.database?.setVerifiedUserCrossSigningKey( newVerified, client.id, userId, publicKey); } @@ -418,8 +419,8 @@ class DeviceKeys extends SignableKey { selfSigned; @override - Future setVerified(bool newVerified, [bool sign = true]) { - super.setVerified(newVerified, sign); + Future setVerified(bool newVerified, [bool sign = true]) async { + await super.setVerified(newVerified, sign); return client?.database ?.setVerifiedUserDeviceKey(newVerified, client.id, userId, deviceId); } diff --git a/lib/src/utils/markdown.dart b/lib/src/utils/markdown.dart index c6b86185..af6ca93c 100644 --- a/lib/src/utils/markdown.dart +++ b/lib/src/utils/markdown.dart @@ -162,7 +162,7 @@ class PillSyntax extends InlineSyntax { } final identifier = match[1]; final element = Element.text('a', identifier); - element.attributes['href'] = 'https://matrix.to/#/${identifier}'; + element.attributes['href'] = 'https://matrix.to/#/$identifier'; parser.addNode(element); return true; } @@ -204,7 +204,7 @@ String markdown(String text, [Map> emotePacks]) { }; for (final tag in otherBlockTags) { // we check for the close tag as the opening one might have attributes - if (ret.contains('')) { + if (ret.contains('')) { stripPTags = false; break; } diff --git a/pubspec.yaml b/pubspec.yaml index 90428883..9c177949 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,8 +30,7 @@ dev_dependencies: test_coverage: ^0.5.0 moor_generator: ^3.4.1 build_runner: ^1.11.1 - pedantic: ^1.9.2 + pedantic: ^1.11.0 dapackages: ^1.4.0 - #flutter_test: # sdk: flutter diff --git a/test/client_test.dart b/test/client_test.dart index 5a4b0230..4112e35a 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -99,7 +99,7 @@ void main() { var firstSyncFuture = matrix.onFirstSync.stream.first; var syncFuture = matrix.onSync.stream.first; - matrix.init( + await matrix.init( newToken: 'abcd', newUserID: '@test:fakeServer.notExisting', newHomeserver: matrix.homeserver, @@ -520,7 +520,7 @@ void main() { databaseBuilder: (_) => database, ); - client1.init( + await client1.init( newToken: 'abc123', newUserID: '@test:fakeServer.notExisting', newHomeserver: Uri.parse('https://fakeServer.notExisting'), @@ -540,7 +540,7 @@ void main() { databaseBuilder: (_) => database, ); - client2.init(); + await client2.init(); await Future.delayed(Duration(milliseconds: 100)); expect(client2.isLogged(), true); diff --git a/test/encryption/encrypt_decrypt_to_device_test.dart b/test/encryption/encrypt_decrypt_to_device_test.dart index 4b72b6c1..cb9d85dd 100644 --- a/test/encryption/encrypt_decrypt_to_device_test.dart +++ b/test/encryption/encrypt_decrypt_to_device_test.dart @@ -55,7 +55,7 @@ void main() { await client.abortSync(); await otherClient.checkHomeserver('https://fakeserver.notexisting', checkWellKnown: false); - otherClient.init( + await otherClient.init( newToken: 'abc', newUserID: '@othertest:fakeServer.notExisting', newHomeserver: otherClient.homeserver, diff --git a/test/encryption/key_verification_test.dart b/test/encryption/key_verification_test.dart index 23001883..33d5a982 100644 --- a/test/encryption/key_verification_test.dart +++ b/test/encryption/key_verification_test.dart @@ -88,7 +88,7 @@ void main() { databaseBuilder: (_) => client1.database); await client2.checkHomeserver('https://fakeserver.notexisting', checkWellKnown: false); - client2.init( + await client2.init( newToken: 'abc', newUserID: '@othertest:fakeServer.notExisting', newHomeserver: client2.homeserver, diff --git a/test/encryption/ssss_test.dart b/test/encryption/ssss_test.dart index ce9da26c..4d278ac0 100644 --- a/test/encryption/ssss_test.dart +++ b/test/encryption/ssss_test.dart @@ -470,15 +470,15 @@ void main() { // with passphrase var newKey = await client.encryption.ssss.createKey('test'); expect(client.encryption.ssss.isKeyValid(newKey.keyId), true); - var testKey = await client.encryption.ssss.open(newKey.keyId); + var testKey = client.encryption.ssss.open(newKey.keyId); await testKey.unlock(passphrase: 'test'); - await testKey.setPrivateKey(newKey.privateKey); + testKey.setPrivateKey(newKey.privateKey); // without passphrase newKey = await client.encryption.ssss.createKey(); expect(client.encryption.ssss.isKeyValid(newKey.keyId), true); - testKey = await client.encryption.ssss.open(newKey.keyId); - await testKey.setPrivateKey(newKey.privateKey); + testKey = client.encryption.ssss.open(newKey.keyId); + testKey.setPrivateKey(newKey.privateKey); }); test('dispose client', () async { diff --git a/test/fake_client.dart b/test/fake_client.dart index 8166ff13..8431d47a 100644 --- a/test/fake_client.dart +++ b/test/fake_client.dart @@ -37,7 +37,7 @@ Future getClient() async { FakeMatrixApi.client = client; await client.checkHomeserver('https://fakeServer.notExisting', checkWellKnown: false); - client.init( + await client.init( newToken: 'abcd', newUserID: '@test:fakeServer.notExisting', newHomeserver: client.homeserver,