Skip to content

Commit 6c54338

Browse files
authored
Make SonarCloud happier (#2850)
* Make SonarCloud happier * Revert one change due to lack of strict mode upstream * Fix typo
1 parent 52932f5 commit 6c54338

23 files changed

+103
-153
lines changed

src/@types/PushRules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export interface IPusher {
169169
lang: string;
170170
profile_tag?: string;
171171
pushkey: string;
172-
enabled?: boolean | null | undefined;
173-
"org.matrix.msc3881.enabled"?: boolean | null | undefined;
172+
enabled?: boolean | null;
173+
"org.matrix.msc3881.enabled"?: boolean | null;
174174
device_id?: string | null;
175175
"org.matrix.msc3881.device_id"?: string | null;
176176
}

src/client.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
29302930
throw new Error("End-to-end encryption disabled");
29312931
}
29322932

2933-
const path = this.makeKeyBackupPath(roomId!, sessionId!, version!);
2933+
const path = this.makeKeyBackupPath(roomId!, sessionId!, version);
29342934
await this.http.authedRequest(
29352935
Method.Put, path.path, path.queryData, data,
29362936
{ prefix: ClientPrefix.V3 },
@@ -3284,7 +3284,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
32843284
throw new Error("End-to-end encryption disabled");
32853285
}
32863286

3287-
const path = this.makeKeyBackupPath(roomId!, sessionId!, version!);
3287+
const path = this.makeKeyBackupPath(roomId!, sessionId!, version);
32883288
await this.http.authedRequest(
32893289
Method.Delete, path.path, path.queryData, undefined,
32903290
{ prefix: ClientPrefix.V3 },
@@ -4181,7 +4181,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
41814181

41824182
return this.sendEvent(
41834183
roomId,
4184-
threadId as (string | null),
4184+
threadId as string | null,
41854185
eventType,
41864186
sendContent,
41874187
txnId,
@@ -5225,7 +5225,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
52255225
];
52265226

52275227
// Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
5228-
let timeline = timelineSet.getTimelineForEvent(events[0].getId()!);
5228+
let timeline = timelineSet.getTimelineForEvent(events[0].getId());
52295229
if (timeline) {
52305230
timeline.getState(EventTimeline.BACKWARDS)!.setUnknownStateEvents(res.state.map(mapper));
52315231
} else {
@@ -6115,15 +6115,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
61156115
// There can be only room-kind push rule per room
61166116
// and its id is the room id.
61176117
if (this.pushRules) {
6118-
if (!this.pushRules[scope] || !this.pushRules[scope].room) {
6119-
return;
6120-
}
6121-
for (let i = 0; i < this.pushRules[scope].room.length; i++) {
6122-
const rule = this.pushRules[scope].room[i];
6123-
if (rule.rule_id === roomId) {
6124-
return rule;
6125-
}
6126-
}
6118+
return this.pushRules[scope]?.room?.find(rule => rule.rule_id === roomId);
61276119
} else {
61286120
throw new Error(
61296121
"SyncApi.sync() must be done before accessing to push rules.",
@@ -6473,8 +6465,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
64736465
// create a new filter
64746466
const createdFilter = await this.createFilter(filter.getDefinition());
64756467

6476-
// debuglog("Created new filter ID %s: %s", createdFilter.filterId,
6477-
// JSON.stringify(createdFilter.getDefinition()));
64786468
this.store.setFilterIdByName(filterName, createdFilter.filterId);
64796469
return createdFilter.filterId!;
64806470
}
@@ -8434,9 +8424,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
84348424
keyAlgorithm = "signed_curve25519";
84358425
}
84368426

8437-
for (let i = 0; i < devices.length; ++i) {
8438-
const userId = devices[i][0];
8439-
const deviceId = devices[i][1];
8427+
for (const [userId, deviceId] of devices) {
84408428
const query = queries[userId] || {};
84418429
queries[userId] = query;
84428430
query[deviceId] = keyAlgorithm;

src/crypto/DeviceList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
230230
}, delay);
231231
}
232232

233-
return savePromise!;
233+
return savePromise;
234234
}
235235

236236
/**

src/crypto/OlmDevice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ export class OlmDevice {
804804
log,
805805
);
806806

807-
return info!;
807+
return info;
808808
}
809809

810810
/**

src/crypto/algorithms/olm.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,10 @@ class OlmEncryption extends EncryptionAlgorithm {
119119

120120
const promises: Promise<void>[] = [];
121121

122-
for (let i = 0; i < users.length; ++i) {
123-
const userId = users[i];
122+
for (const userId of users) {
124123
const devices = this.crypto.getStoredDevicesForUser(userId) || [];
125124

126-
for (let j = 0; j < devices.length; ++j) {
127-
const deviceInfo = devices[j];
125+
for (const deviceInfo of devices) {
128126
const key = deviceInfo.getIdentityKey();
129127
if (key == this.olmDevice.deviceCurve25519Key) {
130128
// don't bother sending to ourself
@@ -304,8 +302,7 @@ class OlmDecryption extends DecryptionAlgorithm {
304302

305303
// try each session in turn.
306304
const decryptionErrors: Record<string, string> = {};
307-
for (let i = 0; i < sessionIds.length; i++) {
308-
const sessionId = sessionIds[i];
305+
for (const sessionId of sessionIds) {
309306
try {
310307
const payload = await this.olmDevice.decryptMessage(
311308
theirDeviceIdentityKey, sessionId, message.type, message.body,

src/crypto/backup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ export class Curve25519 implements BackupAlgorithm {
680680
const backupPubKey = decryption.init_with_private_key(privKey);
681681

682682
if (backupPubKey !== this.authData.public_key) {
683-
// eslint-disable-next-line no-throw-literal
684-
throw { errcode: MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY };
683+
throw new MatrixError({ errcode: MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY });
685684
}
686685

687686
const keys: IMegolmSessionData[] = [];

src/crypto/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,9 +2379,8 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
23792379
*/
23802380
public async getOlmSessionsForUser(userId: string): Promise<Record<string, IUserOlmSession>> {
23812381
const devices = this.getStoredDevicesForUser(userId) || [];
2382-
const result = {};
2383-
for (let j = 0; j < devices.length; ++j) {
2384-
const device = devices[j];
2382+
const result: { [deviceId: string]: IUserOlmSession } = {};
2383+
for (const device of devices) {
23852384
const deviceKey = device.getIdentityKey();
23862385
const sessions = await this.olmDevice.getSessionInfoForDevice(deviceKey);
23872386

@@ -2682,14 +2681,11 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
26822681
): Promise<Record<string, Record<string, olmlib.IOlmSessionResult>>> {
26832682
const devicesByUser: Record<string, DeviceInfo[]> = {};
26842683

2685-
for (let i = 0; i < users.length; ++i) {
2686-
const userId = users[i];
2684+
for (const userId of users) {
26872685
devicesByUser[userId] = [];
26882686

26892687
const devices = this.getStoredDevicesForUser(userId) || [];
2690-
for (let j = 0; j < devices.length; ++j) {
2691-
const deviceInfo = devices[j];
2692-
2688+
for (const deviceInfo of devices) {
26932689
const key = deviceInfo.getIdentityKey();
26942690
if (key == this.olmDevice.deviceCurve25519Key) {
26952691
// don't bother setting up session to ourself

src/crypto/olmlib.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ export async function ensureOlmSessionsForDevices(
335335
const promises: Promise<void>[] = [];
336336
for (const [userId, devices] of Object.entries(devicesByUser)) {
337337
const userRes = otkResult[userId] || {};
338-
for (let j = 0; j < devices.length; j++) {
339-
const deviceInfo = devices[j];
338+
for (const deviceInfo of devices) {
340339
const deviceId = deviceInfo.deviceId;
341340
const key = deviceInfo.getIdentityKey();
342341

src/filter-component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ export class FilterComponent {
150150
},
151151
};
152152

153-
for (let n = 0; n < Object.keys(literalKeys).length; n++) {
154-
const name = Object.keys(literalKeys)[n];
153+
for (const name in literalKeys) {
155154
const matchFunc = literalKeys[name];
156155
const notName = "not_" + name;
157156
const disallowedValues: string[] = this.filterJson[notName];

src/interactive-auth.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,6 @@ export class InteractiveAuth {
631631
*/
632632
private firstUncompletedStage(flow: IFlow): AuthType | undefined {
633633
const completed = this.data.completed || [];
634-
for (let i = 0; i < flow.stages.length; ++i) {
635-
const stageType = flow.stages[i];
636-
if (completed.indexOf(stageType) === -1) {
637-
return stageType;
638-
}
639-
}
634+
return flow.stages.find(stageType => !completed.includes(stageType));
640635
}
641636
}

0 commit comments

Comments
 (0)