Skip to content

Commit b896111

Browse files
authored
Apply corrections identified by SonarQube (matrix-org#2336)
* Apply corrections identified by SonarQube * Apply corrections identified by SonarQube * Make type more flexible
1 parent 6137afe commit b896111

File tree

9 files changed

+28
-32
lines changed

9 files changed

+28
-32
lines changed

src/autodiscovery.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,20 @@ export class AutoDiscovery {
249249

250250
// Step 7: Copy any other keys directly into the clientConfig. This is for
251251
// things like custom configuration of services.
252-
Object.keys(wellknown)
253-
.map((k) => {
254-
if (k === "m.homeserver" || k === "m.identity_server") {
255-
// Only copy selected parts of the config to avoid overwriting
256-
// properties computed by the validation logic above.
257-
const notProps = ["error", "state", "base_url"];
258-
for (const prop of Object.keys(wellknown[k])) {
259-
if (notProps.includes(prop)) continue;
260-
clientConfig[k][prop] = wellknown[k][prop];
261-
}
262-
} else {
263-
// Just copy the whole thing over otherwise
264-
clientConfig[k] = wellknown[k];
252+
Object.keys(wellknown).forEach((k) => {
253+
if (k === "m.homeserver" || k === "m.identity_server") {
254+
// Only copy selected parts of the config to avoid overwriting
255+
// properties computed by the validation logic above.
256+
const notProps = ["error", "state", "base_url"];
257+
for (const prop of Object.keys(wellknown[k])) {
258+
if (notProps.includes(prop)) continue;
259+
clientConfig[k][prop] = wellknown[k][prop];
265260
}
266-
});
261+
} else {
262+
// Just copy the whole thing over otherwise
263+
clientConfig[k] = wellknown[k];
264+
}
265+
});
267266

268267
// Step 8: Give the config to the caller (finally)
269268
return Promise.resolve(clientConfig);

src/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
34153415
*/
34163416
public setIgnoredUsers(userIds: string[], callback?: Callback): Promise<{}> {
34173417
const content = { ignored_users: {} };
3418-
userIds.map((u) => content.ignored_users[u] = {});
3418+
userIds.forEach((u) => {
3419+
content.ignored_users[u] = {};
3420+
});
34193421
return this.setAccountData("m.ignored_user_list", content, callback);
34203422
}
34213423

src/crypto/DeviceList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
309309
*/
310310
private getDevicesFromStore(userIds: string[]): DeviceInfoMap {
311311
const stored: DeviceInfoMap = {};
312-
userIds.map((u) => {
312+
userIds.forEach((u) => {
313313
stored[u] = {};
314314
const devices = this.getStoredDevicesForUser(u) || [];
315-
devices.map(function(dev) {
315+
devices.forEach(function(dev) {
316316
stored[u][dev.deviceId] = dev;
317317
});
318318
});

src/crypto/backup.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,7 @@ export class BackupManager {
375375
);
376376
if (device) {
377377
sigInfo.device = device;
378-
sigInfo.deviceTrust = await this.baseApis.checkDeviceTrust(
379-
this.baseApis.getUserId(), sigInfo.deviceId,
380-
);
378+
sigInfo.deviceTrust = this.baseApis.checkDeviceTrust(this.baseApis.getUserId(), sigInfo.deviceId);
381379
try {
382380
await verifySignature(
383381
this.baseApis.crypto.olmDevice,
@@ -495,7 +493,7 @@ export class BackupManager {
495493
rooms[roomId] = { sessions: {} };
496494
}
497495

498-
const sessionData = await this.baseApis.crypto.olmDevice.exportInboundGroupSession(
496+
const sessionData = this.baseApis.crypto.olmDevice.exportInboundGroupSession(
499497
session.senderKey, session.sessionId, session.sessionData,
500498
);
501499
sessionData.algorithm = MEGOLM_ALGORITHM;

src/crypto/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
10261026
const decodedBackupKey = new Uint8Array(olmlib.decodeBase64(
10271027
fixedBackupKey || sessionBackupKey,
10281028
));
1029-
await builder.addSessionBackupPrivateKeyToCache(decodedBackupKey);
1029+
builder.addSessionBackupPrivateKeyToCache(decodedBackupKey);
10301030
} else if (this.backupManager.getKeyBackupEnabled()) {
10311031
// key backup is enabled but we don't have a session backup key in SSSS: see if we have one in
10321032
// the cache or the user can provide one, and if so, write it to SSSS

src/crypto/verification/request/VerificationRequest.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,7 @@ export class VerificationRequest<
796796
}
797797

798798
private setupTimeout(phase: Phase): void {
799-
const shouldTimeout = !this.timeoutTimer && !this.observeOnly &&
800-
phase === PHASE_REQUESTED;
799+
const shouldTimeout = !this.timeoutTimer && !this.observeOnly && phase === PHASE_REQUESTED;
801800

802801
if (shouldTimeout) {
803802
this.timeoutTimer = setTimeout(this.cancelOnTimeout, this.timeout);
@@ -814,15 +813,15 @@ export class VerificationRequest<
814813
}
815814
}
816815

817-
private cancelOnTimeout = () => {
816+
private cancelOnTimeout = async () => {
818817
try {
819818
if (this.initiatedByMe) {
820-
this.cancel({
819+
await this.cancel({
821820
reason: "Other party didn't accept in time",
822821
code: "m.timeout",
823822
});
824823
} else {
825-
this.cancel({
824+
await this.cancel({
826825
reason: "User didn't accept in time",
827826
code: "m.timeout",
828827
});

src/http-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ export class AbortError extends Error {
11051105
* @return {any} the result of the network operation
11061106
* @throws {ConnectionError} If after maxAttempts the callback still throws ConnectionError
11071107
*/
1108-
export async function retryNetworkOperation<T>(maxAttempts: number, callback: () => T): Promise<T> {
1108+
export async function retryNetworkOperation<T>(maxAttempts: number, callback: () => Promise<T>): Promise<T> {
11091109
let attempts = 0;
11101110
let lastConnectionError = null;
11111111
while (attempts < maxAttempts) {

src/store/indexeddb-local-backend.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,7 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
530530
const txn = this.db.transaction(["client_options"], "readonly");
531531
const store = txn.objectStore("client_options");
532532
return selectQuery(store, undefined, (cursor) => {
533-
if (cursor.value && cursor.value && cursor.value.options) {
534-
return cursor.value.options;
535-
}
533+
return cursor.value?.options;
536534
}).then((results) => results[0]);
537535
});
538536
}

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ export function defer<T = void>(): IDeferred<T> {
464464
}
465465

466466
export async function promiseMapSeries<T>(
467-
promises: T[],
467+
promises: Array<T | Promise<T>>,
468468
fn: (t: T) => void,
469469
): Promise<void> {
470470
for (const o of promises) {

0 commit comments

Comments
 (0)