Skip to content

Commit c7aa9a9

Browse files
authored
Make code comply with oxlint suspicious ruleset (#5435)
* Use `node:` imports * Remove spurious disablements * Fix imports * Fix badly written test * Make oxlint happy with empty catch statements * Simplify some assertions * Make code comply with category restriction & reportUnusedDisableDirectives=warn * Make code comply with oxlint suspicious ruleset * Delint * Iterate
1 parent 0d8558d commit c7aa9a9

93 files changed

Lines changed: 624 additions & 646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxlintrc.jsonc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"correctness": "error",
66
"perf": "error",
77
"restriction": "error",
8+
"suspicious": "error",
89
},
910
"options": {
1011
"typeAware": true,
@@ -104,6 +105,13 @@
104105
"no-void": "off",
105106
"no-bitwise": "off",
106107
"no-eq-null": "off",
108+
"unicorn/no-array-sort": "off",
109+
"unicorn/no-array-reverse": "off",
110+
"typescript/no-unnecessary-type-parameters": "off",
111+
"typescript/no-unnecessary-boolean-literal-compare": "off",
112+
"typescript/no-extraneous-class": "off",
113+
"promise/always-return": "off",
114+
"unicorn/prefer-add-event-listener": "off",
107115

108116
// Disable some rules by default for them to be enabled for `src` via overrides
109117
"no-console": "off",
@@ -133,6 +141,8 @@
133141
"typescript/no-import-type-side-effects": "off",
134142
"typescript/use-unknown-in-catch-callback-variable": "off",
135143
"typescript/no-invalid-void-type": "off", // https://github.com/oxc-project/oxc/issues/20280
144+
"typescript/no-unsafe-enum-comparison": "off",
145+
"typescript/no-unnecessary-type-conversion": "off",
136146
"no-param-reassign": "off",
137147
"typescript/no-explicit-any": "off",
138148
"import/no-cycle": "off",
@@ -142,6 +152,11 @@
142152
"guard-for-in": "error",
143153
"complexity": "off",
144154
"no-empty-function": "off",
155+
"no-underscore-dangle": "off",
156+
"no-shadow": "off",
157+
"unicorn/consistent-function-scoping": "off",
158+
"typescript/no-unsafe-type-assertion": "off",
159+
"typescript/consistent-return": "off",
145160
},
146161
"overrides": [
147162
{
@@ -164,6 +179,7 @@
164179
"typescript/unbound-method": "off",
165180
"typescript/no-floating-promises": "off",
166181
"typescript/no-misused-spread": "off",
182+
"typescript/consistent-return": "off",
167183
"vitest/require-mock-type-parameters": "off",
168184
"vitest/no-disabled-tests": "off",
169185
"vitest/no-conditional-expect": "off",
@@ -191,7 +207,18 @@
191207
],
192208
},
193209
],
210+
"unicorn/consistent-function-scoping": "off",
194211
"jsdoc/check-tag-names": "off",
212+
"no-shadow": "off",
213+
"import/no-unassigned-import": [
214+
"error",
215+
{
216+
"allow": ["fake-indexeddb/auto"],
217+
},
218+
],
219+
"promise/no-promise-in-callback": "off",
220+
"no-new": "off",
221+
"unicorn/prefer-add-event-listener": "off",
195222
},
196223
},
197224
{
@@ -221,5 +248,6 @@
221248
"typescript/no-require-imports": "off",
222249
},
223250
},
251+
{ "files": ["**/*.d.ts"], "rules": { "unicorn/require-module-specifiers": "off" } },
224252
],
225253
}

spec/integ/crypto/cross-signing.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("cross-signing", () => {
137137
// check that the cross-signing keys have been uploaded
138138
expect(fetchMock.callHistory.called("upload-cross-signing-keys")).toBeTruthy();
139139
const keysOpts = fetchMock.callHistory.lastCall("upload-cross-signing-keys")!.options;
140-
const keysBody = JSON.parse(keysOpts!.body as string);
140+
const keysBody = JSON.parse(keysOpts.body as string);
141141
expect(keysBody.auth).toEqual(authDict); // check uia dict was passed
142142
// there should be a key of each type
143143
// master key is signed by the device
@@ -151,7 +151,7 @@ describe("cross-signing", () => {
151151
// check the publish call
152152
expect(fetchMock.callHistory.called("upload-sigs")).toBeTruthy();
153153
const sigsOpts = fetchMock.callHistory.lastCall("upload-sigs")!.options;
154-
const body = JSON.parse(sigsOpts!.body as string);
154+
const body = JSON.parse(sigsOpts.body as string);
155155
// there should be a signature for our device, by our self-signing key.
156156
expect(body).toHaveProperty([TEST_USER_ID, TEST_DEVICE_ID, "signatures", TEST_USER_ID, sskId]);
157157
});
@@ -234,7 +234,7 @@ describe("cross-signing", () => {
234234
// Expect the signature to be uploaded
235235
expect(fetchMock.callHistory.called("upload-sigs")).toBeTruthy();
236236
const sigsOpts = fetchMock.callHistory.lastCall("upload-sigs")!.options;
237-
const body = JSON.parse(sigsOpts!.body as string);
237+
const body = JSON.parse(sigsOpts.body as string);
238238
// the device should have a signature with the public self cross signing keys.
239239
expect(body).toHaveProperty([
240240
TEST_USER_ID,
@@ -476,7 +476,7 @@ describe("cross-signing", () => {
476476
// check that a sig for the device was uploaded
477477
const calls = fetchMock.callHistory.calls("upload-sigs");
478478
expect(calls.length).toEqual(1);
479-
const body = JSON.parse(calls[0].options!.body as string);
479+
const body = JSON.parse(calls[0].options.body as string);
480480
const deviceSig = body[aliceClient.getSafeUserId()][testData.TEST_DEVICE_ID];
481481
expect(deviceSig).toHaveProperty("signatures");
482482
});

spec/integ/crypto/crypto.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ describe("crypto", () => {
11581158
// it probably won't be decrypted yet, because it takes a while to process the olm keys
11591159
const decryptedEvent = await testUtils.awaitDecryption(event, { waitOnDecryptionFailure: true });
11601160
expect(decryptedEvent.getRoomId()).toEqual(ROOM_ID);
1161-
expect(decryptedEvent.getContent<IContent>()).toEqual({});
1161+
expect(decryptedEvent.getContent()).toEqual({});
11621162
expect(decryptedEvent.getClearContent()).toBeUndefined();
11631163
});
11641164

@@ -1196,7 +1196,7 @@ describe("crypto", () => {
11961196
// and wait for the outgoing requests
11971197
const inboundGroupSession = await inboundGroupSessionPromise;
11981198
const encryptedMessageContent = await reqProm;
1199-
const msg: any = inboundGroupSession.decrypt(encryptedMessageContent!.ciphertext);
1199+
const msg: any = inboundGroupSession.decrypt(encryptedMessageContent.ciphertext);
12001200
logger.log("Decrypted received megolm message", msg);
12011201

12021202
// at this point, the request to send the room message has been made, but not completed.
@@ -1229,7 +1229,7 @@ describe("crypto", () => {
12291229
});
12301230
await syncPromise(aliceClient);
12311231

1232-
const timelineEvents = aliceClient.getRoom(testData.TEST_ROOM_ID)!.getLiveTimeline()!.getEvents();
1232+
const timelineEvents = aliceClient.getRoom(testData.TEST_ROOM_ID)!.getLiveTimeline().getEvents();
12331233
const lastEvent = timelineEvents[timelineEvents.length - 1];
12341234
expect(lastEvent.getId()).toEqual("$event_id");
12351235

@@ -1864,11 +1864,11 @@ describe("crypto", () => {
18641864
expect(activeBackup).toStrictEqual(backupVersion);
18651865

18661866
// check that there is a MSK signature
1867-
const signatures = (await aliceClient.getCrypto()!.checkKeyBackupAndEnable())!.backupInfo.auth_data!
1867+
const signatures = (await aliceClient.getCrypto()!.checkKeyBackupAndEnable())!.backupInfo.auth_data
18681868
.signatures;
18691869
expect(signatures).toBeDefined();
18701870
expect(signatures![aliceClient.getUserId()!]).toBeDefined();
1871-
const mskId = await aliceClient.getCrypto()!.getCrossSigningKeyId(CrossSigningKey.Master)!;
1871+
const mskId = await aliceClient.getCrypto()!.getCrossSigningKeyId(CrossSigningKey.Master);
18721872
expect(signatures![aliceClient.getUserId()!][`ed25519:${mskId}`]).toBeDefined();
18731873
});
18741874

@@ -1907,7 +1907,7 @@ describe("crypto", () => {
19071907
const check = await aliceClient.getCrypto()!.checkKeyBackupAndEnable();
19081908
fetchMock.get(
19091909
`path:/_matrix/client/v3/room_keys/version/${check!.backupInfo.version}`,
1910-
check!.backupInfo!,
1910+
check!.backupInfo,
19111911
);
19121912

19131913
// Import a new key that should be uploaded

spec/integ/crypto/history-sharing.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ describe("History Sharing", () => {
709709
sender: aliceClient.getSafeUserId(),
710710
content: firstMessage,
711711
event_id: "$event_id",
712-
}) as any,
712+
}),
713713
);
714714
bobSyncResponder.sendOrQueueSyncResponse(bobSyncResponse);
715715
await syncPromise(bobClient);
@@ -797,7 +797,7 @@ describe("History Sharing", () => {
797797
sender: bobClient.getSafeUserId(),
798798
content: bobEventM1Content,
799799
event_id: "$event_id_m1",
800-
}) as any,
800+
}),
801801
);
802802
syncResponse.to_device = {
803803
events: [
@@ -873,7 +873,7 @@ describe("History Sharing", () => {
873873
sender: bobClient.getSafeUserId(),
874874
content: bobEventM1Content,
875875
event_id: "$event_id_m1",
876-
}) as any,
876+
}),
877877
);
878878
charlieSyncResponder.sendOrQueueSyncResponse(syncResponse);
879879
await syncPromise(charlieClient);
@@ -939,7 +939,7 @@ describe("History Sharing", () => {
939939
type: EventType.RoomMember,
940940
sender: charlieClient.getSafeUserId(),
941941
state_key: charlieClient.getSafeUserId(),
942-
}) as any,
942+
}),
943943
],
944944
};
945945
} else {
@@ -949,13 +949,13 @@ describe("History Sharing", () => {
949949
type: EventType.RoomMember,
950950
sender: charlieClient.getSafeUserId(),
951951
state_key: charlieClient.getSafeUserId(),
952-
}) as any,
952+
}),
953953
mkEventCustom({
954954
content: { membership: config.leftState },
955955
type: EventType.RoomMember,
956956
sender: charlieClient.getSafeUserId(),
957957
state_key: charlieClient.getSafeUserId(),
958-
}) as any,
958+
}),
959959
);
960960
}
961961
// Bob syncs to learn about Charlie's leaving (and joining if non-gappy).

spec/integ/crypto/megolm-backup.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { type Mocked } from "vitest";
2222
import {
2323
createClient,
2424
encodeBase64,
25-
type IContent,
2625
type ICreateClientOpts,
2726
type IEvent,
2827
type IMegolmSessionData,
@@ -240,7 +239,7 @@ describe("megolm-keys backup", () => {
240239

241240
// Eventually, decryption succeeds.
242241
await awaitDecryption(event, { waitOnDecryptionFailure: true });
243-
expect(event.getContent<IContent>()).toEqual(testData.CLEAR_EVENT.content);
242+
expect(event.getContent()).toEqual(testData.CLEAR_EVENT.content);
244243
});
245244

246245
it("handles error on backup query gracefully", async () => {
@@ -329,7 +328,7 @@ describe("megolm-keys backup", () => {
329328
const check = await aliceCrypto.checkKeyBackupAndEnable();
330329
await aliceCrypto.storeSessionBackupPrivateKey(
331330
decodeRecoveryKey(testData.BACKUP_DECRYPTION_KEY_BASE58),
332-
check!.backupInfo!.version,
331+
check!.backupInfo.version,
333332
);
334333

335334
const result = await advanceTimersUntil(aliceCrypto.restoreKeyBackup());
@@ -379,7 +378,7 @@ describe("megolm-keys backup", () => {
379378

380379
await aliceCrypto.storeSessionBackupPrivateKey(
381380
decodeRecoveryKey(testData.BACKUP_DECRYPTION_KEY_BASE58),
382-
check!.backupInfo!.version,
381+
check!.backupInfo.version,
383382
);
384383

385384
const progressCallback = vi.fn();
@@ -438,7 +437,7 @@ describe("megolm-keys backup", () => {
438437
const check = await aliceCrypto.checkKeyBackupAndEnable();
439438
await aliceCrypto.storeSessionBackupPrivateKey(
440439
decodeRecoveryKey(testData.BACKUP_DECRYPTION_KEY_BASE58),
441-
check!.backupInfo!.version,
440+
check!.backupInfo.version,
442441
);
443442

444443
const progressCallback = vi.fn();
@@ -473,7 +472,7 @@ describe("megolm-keys backup", () => {
473472
// DecryptSessions does not reject on decryption failure, but just skip the key
474473
decryptSessions: vi.fn().mockImplementation((sessions) => {
475474
// simulate fail to decrypt 2 keys out of all
476-
const decrypted = [];
475+
const decrypted: Mocked<IMegolmSessionData>[] = [];
477476
const keys = Object.keys(sessions);
478477
for (let i = 0; i < keys.length - decryptionFailureCount; i++) {
479478
decrypted.push({
@@ -495,7 +494,7 @@ describe("megolm-keys backup", () => {
495494
const check = await aliceCrypto.checkKeyBackupAndEnable();
496495
await aliceCrypto.storeSessionBackupPrivateKey(
497496
decodeRecoveryKey(testData.BACKUP_DECRYPTION_KEY_BASE58),
498-
check!.backupInfo!.version,
497+
check!.backupInfo.version,
499498
);
500499

501500
const result = await aliceCrypto.restoreKeyBackup();
@@ -1132,7 +1131,7 @@ describe("megolm-keys backup", () => {
11321131
const event = room.getLiveTimeline().getEvents()[0];
11331132
await advanceTimersUntil(awaitDecryption(event, { waitOnDecryptionFailure: true }));
11341133

1135-
expect(event.getContent<IContent>()).toEqual(testData.CLEAR_EVENT.content);
1134+
expect(event.getContent()).toEqual(testData.CLEAR_EVENT.content);
11361135

11371136
// =====
11381137
// Second suppose now that the backup has changed to version 2

spec/integ/crypto/olm-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export async function expectSendMegolmMessageEvent(
518518
// In some of the tests, the room key is sent *after* the actual event, so we may need to wait for it now.
519519
const inboundGroupSession = await inboundGroupSessionPromise;
520520

521-
const r: any = inboundGroupSession.decrypt(encryptedMessageContent!.ciphertext);
521+
const r: any = inboundGroupSession.decrypt(encryptedMessageContent.ciphertext);
522522
logger.log("Decrypted received megolm message", r);
523523
return JSON.parse(r.plaintext);
524524
}
@@ -541,7 +541,7 @@ export async function expectSendMegolmStateEvent(
541541
// In some of the tests, the room key is sent *after* the actual event, so we may need to wait for it now.
542542
const inboundGroupSession = await inboundGroupSessionPromise;
543543

544-
const r: any = inboundGroupSession.decrypt(encryptedStateContent!.ciphertext);
544+
const r: any = inboundGroupSession.decrypt(encryptedStateContent.ciphertext);
545545
logger.log("Decrypted received megolm state event", r);
546546
return JSON.parse(r.plaintext);
547547
}

spec/integ/crypto/verification.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ describe("verification", () => {
12841284
signedNonMatchingBackupInfo,
12851285
]);
12861286

1287-
e2eKeyResponder.addDeviceKeys(bootstrapped.device_keys![TEST_USER_ID]![olmDeviceId]);
1287+
e2eKeyResponder.addDeviceKeys(bootstrapped.device_keys![TEST_USER_ID][olmDeviceId]);
12881288
e2eKeyResponder.addCrossSigningData(bootstrapped);
12891289

12901290
usermasterPubKey = Object.values(bootstrapped.master_keys![TEST_USER_ID].keys)[0];
@@ -1529,7 +1529,7 @@ describe("verification", () => {
15291529
recipientEd25519Key: e2eKeyReceiver.getSigningKey(),
15301530
p2pSession: p2pSession,
15311531
olmAccount: testOlmAccount,
1532-
requestId: requestId!,
1532+
requestId: requestId,
15331533
secret: secret,
15341534
});
15351535

spec/integ/matrix-client-event-emitter.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ describe("MatrixClient events", function () {
3939
const testClient = new TestClient(selfUserId, "DEVICE", selfAccessToken);
4040
const client = testClient.client;
4141
const httpBackend = testClient.httpBackend;
42-
httpBackend!.when("GET", "/versions").respond(200, {});
43-
httpBackend!.when("GET", "/pushrules").respond(200, {});
44-
httpBackend!.when("POST", "/filter").respond(200, { filter_id: "a filter id" });
42+
httpBackend.when("GET", "/versions").respond(200, {});
43+
httpBackend.when("GET", "/pushrules").respond(200, {});
44+
httpBackend.when("POST", "/filter").respond(200, { filter_id: "a filter id" });
4545

46-
return [client!, httpBackend];
46+
return [client, httpBackend];
4747
};
4848

4949
beforeEach(function () {

0 commit comments

Comments
 (0)