Enable tsconfig noUncheckedIndexedAccess

This commit is contained in:
Jamie
2026-03-12 16:24:01 -07:00
committed by GitHub
parent 34b0f9cd50
commit 1d45a52da7
311 changed files with 2146 additions and 1589 deletions

View File

@@ -64,10 +64,12 @@ describe('getFontNameByTextScript', () => {
const text = 'abc';
assert.throws(() => {
// @ts-expect-error invalid text style
getFontNameByTextScript(text, -1);
});
assert.throws(() => {
// @ts-expect-error invalid text style
getFontNameByTextScript(text, 99);
});
});

View File

@@ -334,8 +334,8 @@ describe('iterable utilities', () => {
it('returns a map of groups', () => {
assert.deepEqual(
groupBy(
['apple', 'aardvark', 'orange', 'orange', 'zebra'],
str => str[0]
['apple', 'aardvark', 'orange', 'orange', 'zebra'] as const,
str => str[0] ?? ''
),
{
a: ['apple', 'aardvark'],

View File

@@ -35,12 +35,13 @@ const BUCKET_SIZES = [
40453710, 42476396, 44600216, 46830227, 49171738, 51630325, 54211841,
56922433, 59768555, 62756983, 65894832, 69189573, 72649052, 76281505,
80095580, 84100359, 88305377, 92720646, 97356678, 102224512, 107335738,
];
] as const;
describe('logPadSize', () => {
it('properly calculates first bucket', () => {
for (let size = 0, max = BUCKET_SIZES[0]; size < max; size += 1) {
assert.strictEqual(BUCKET_SIZES[0], logPadSize(size));
const max = BUCKET_SIZES[0];
for (let size = 0; size < max; size += 1) {
assert.strictEqual(max, logPadSize(size));
}
});
@@ -48,29 +49,27 @@ describe('logPadSize', () => {
let count = 0;
const failures = new Array<string>();
for (let i = 0, max = BUCKET_SIZES.length - 1; i < max; i += 1) {
for (const [i, bucketSize] of BUCKET_SIZES.slice(0, -1).entries()) {
// Exact
if (BUCKET_SIZES[i] !== logPadSize(BUCKET_SIZES[i])) {
if (bucketSize !== logPadSize(bucketSize)) {
count += 1;
failures.push(
`${BUCKET_SIZES[i]} does not equal ${logPadSize(BUCKET_SIZES[i])}`
);
failures.push(`${bucketSize} does not equal ${logPadSize(bucketSize)}`);
}
// Just under
if (BUCKET_SIZES[i] !== logPadSize(BUCKET_SIZES[i] - 1)) {
if (bucketSize !== logPadSize(bucketSize - 1)) {
count += 1;
failures.push(
`${BUCKET_SIZES[i]} does not equal ${logPadSize(BUCKET_SIZES[i] - 1)}`
`${bucketSize} does not equal ${logPadSize(bucketSize - 1)}`
);
}
// Just over
if (BUCKET_SIZES[i + 1] !== logPadSize(BUCKET_SIZES[i] + 1)) {
if (BUCKET_SIZES[i + 1] !== logPadSize(bucketSize + 1)) {
count += 1;
failures.push(
`${BUCKET_SIZES[i + 1]} does not equal ` +
`${logPadSize(BUCKET_SIZES[i] + 1)}`
`${logPadSize(bucketSize + 1)}`
);
}
}

View File

@@ -1,9 +1,11 @@
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { assert } from 'chai';
import type { MessageAttributesType } from '../../model-types.d.ts';
import type {
EditHistoryType,
MessageAttributesType,
} from '../../model-types.d.ts';
import type { AttachmentType } from '../../types/Attachment.std.js';
import { IMAGE_JPEG, LONG_MESSAGE } from '../../types/MIME.std.js';
import { generateMessageId } from '../../util/generateMessageId.node.js';
@@ -84,80 +86,78 @@ describe('ensureBodyAttachmentsAreSeparated', () => {
assert.deepEqual(result.bodyAttachment, msg.bodyAttachment);
});
it('separates first body attachment out for all editHistory', () => {
const normalAttachment = composeAttachment({
clientUuid: 'normal attachment',
contentType: IMAGE_JPEG,
});
const longMessageAttachment1 = composeAttachment({
clientUuid: 'long message attachment 1',
contentType: LONG_MESSAGE,
});
const longMessageAttachment2 = composeAttachment({
clientUuid: 'long message attachment 2',
contentType: LONG_MESSAGE,
});
const editAttachment1 = composeAttachment({
clientUuid: 'edit attachment 1',
contentType: IMAGE_JPEG,
});
const editAttachment2 = composeAttachment({
clientUuid: 'edit attachment 2',
contentType: IMAGE_JPEG,
});
const bodyAttachment = composeAttachment({
clientUuid: 'long message attachment already as bodyattachment',
contentType: LONG_MESSAGE,
});
const edit1: EditHistoryType = {
timestamp: Date.now(),
received_at: Date.now(),
attachments: [
editAttachment1,
longMessageAttachment1,
longMessageAttachment2,
],
};
const edit2: EditHistoryType = {
timestamp: Date.now(),
received_at: Date.now(),
bodyAttachment,
attachments: [editAttachment1, editAttachment2],
};
const msg = composeMessage({
attachments: [
composeAttachment({
clientUuid: 'normal attachment',
contentType: IMAGE_JPEG,
}),
composeAttachment({
clientUuid: 'long message attachment 1',
contentType: LONG_MESSAGE,
}),
composeAttachment({
clientUuid: 'long message attachment 2',
contentType: LONG_MESSAGE,
}),
],
editHistory: [
{
timestamp: Date.now(),
received_at: Date.now(),
attachments: [
composeAttachment({
clientUuid: 'edit attachment',
contentType: IMAGE_JPEG,
}),
composeAttachment({
clientUuid: 'long message attachment 1',
contentType: LONG_MESSAGE,
}),
composeAttachment({
clientUuid: 'long message attachment 2',
contentType: LONG_MESSAGE,
}),
],
},
{
timestamp: Date.now(),
received_at: Date.now(),
bodyAttachment: composeAttachment({
clientUuid: 'long message attachment already as bodyattachment',
contentType: LONG_MESSAGE,
}),
attachments: [
composeAttachment({
clientUuid: 'edit attachment 1',
contentType: IMAGE_JPEG,
}),
composeAttachment({
clientUuid: 'edit attachment 2',
contentType: IMAGE_JPEG,
}),
],
},
normalAttachment,
longMessageAttachment1,
longMessageAttachment2,
],
editHistory: [edit1, edit2],
});
const result = ensureBodyAttachmentsAreSeparated(msg, {
logId: 'test',
logger,
});
assert.deepEqual(result.attachments, [msg.attachments?.[0]]);
assert.deepEqual(result.bodyAttachment, msg.attachments?.[1]);
assert.deepEqual(result.attachments, [normalAttachment]);
assert.deepEqual(result.bodyAttachment, longMessageAttachment1);
assert.deepEqual(result.editHistory, [
{
...msg.editHistory![0],
attachments: [msg.editHistory![0].attachments![0]],
bodyAttachment: msg.editHistory![0].attachments![1],
...edit1,
attachments: [editAttachment1],
bodyAttachment: longMessageAttachment1,
},
{
...msg.editHistory![1],
attachments: [
msg.editHistory![1].attachments![0],
msg.editHistory![1].attachments![1],
],
bodyAttachment: msg.editHistory![1].bodyAttachment,
...edit2,
attachments: [editAttachment1, editAttachment2],
bodyAttachment,
},
]);
});