tsc:allowUnreachableCode, eslint:no-unreachable, assert->assertDev

This commit is contained in:
Jamie Kyle 2022-09-15 12:17:15 -07:00 committed by GitHub
parent f627a05cf8
commit eb10aafd7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 213 additions and 176 deletions

View file

@ -22,7 +22,10 @@ export function softAssert(condition: unknown, message: string): void {
/**
* In production, logs an error and continues. In all other environments, throws an error.
*/
export function assert(condition: unknown, message: string): asserts condition {
export function assertDev(
condition: unknown,
message: string
): asserts condition {
if (!condition) {
const err = new Error(message);
if (getEnvironment() !== Environment.Production) {

View file

@ -31,7 +31,7 @@ import { renderClearingDataView } from '../shims/renderClearingDataView';
import * as universalExpireTimer from './universalExpireTimer';
import { PhoneNumberDiscoverability } from './phoneNumberDiscoverability';
import { PhoneNumberSharingMode } from './phoneNumberSharingMode';
import { assert } from './assert';
import { assertDev } from './assert';
import * as durations from './durations';
import { isPhoneNumberSharingEnabled } from './isPhoneNumberSharingEnabled';
import { parseE164FromSignalDotMeHash } from './sgnlHref';
@ -360,7 +360,7 @@ export function createIPCEvents(
const conversationId =
window.ConversationController.getOurConversationIdOrThrow();
const account = window.ConversationController.get(conversationId);
assert(account, "Account wasn't found");
assertDev(account, "Account wasn't found");
account.captureChange('universalExpireTimer');
@ -369,7 +369,7 @@ export function createIPCEvents(
const selectedId = state.conversations.selectedConversationId;
if (selectedId) {
const conversation = window.ConversationController.get(selectedId);
assert(conversation, "Conversation wasn't found");
assertDev(conversation, "Conversation wasn't found");
await conversation.updateLastMessage();
}

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { getOwn } from './getOwn';
import { assert } from './assert';
import { assertDev } from './assert';
export const deconstructLookup = <T>(
lookup: Record<string, T>,
@ -14,7 +14,7 @@ export const deconstructLookup = <T>(
if (value) {
result.push(value);
} else {
assert(false, `deconstructLookup: lookup failed for ${key}; dropping`);
assertDev(false, `deconstructLookup: lookup failed for ${key}; dropping`);
}
});
return result;

View file

@ -3,7 +3,7 @@
import emojiRegex from 'emoji-regex';
import { assert } from './assert';
import { assertDev } from './assert';
import { take } from './iterables';
const REGEXP = emojiRegex();
@ -31,7 +31,7 @@ export function splitByEmoji(value: string): ReadonlyArray<SplitElement> {
result.push({ type: 'emoji', value: match[0] });
assert(match.index !== undefined, '`matchAll` should provide indices');
assertDev(match.index !== undefined, '`matchAll` should provide indices');
lastIndex = match.index + match[0].length;
}

View file

@ -3,7 +3,7 @@
import type { ConversationType } from '../state/ducks/conversations';
import type { ProfileRequestDataType } from '../textsecure/WebAPI';
import { assert } from './assert';
import { assertDev } from './assert';
import * as Bytes from '../Bytes';
import {
PaddedLengths,
@ -27,8 +27,8 @@ export async function encryptProfileData(
uuid,
} = conversation;
assert(profileKey, 'profileKey');
assert(uuid, 'uuid');
assertDev(profileKey, 'profileKey');
assertDev(uuid, 'uuid');
const keyBuffer = Bytes.fromBase64(profileKey);

View file

@ -5,7 +5,7 @@ import { PublicKey, Fingerprint } from '@signalapp/libsignal-client';
import type { ConversationType } from '../state/ducks/conversations';
import { UUID } from '../types/UUID';
import { assert } from './assert';
import { assertDev } from './assert';
import * as log from '../logging/log';
export async function generateSecurityNumber(
@ -63,7 +63,7 @@ export async function generateSecurityNumberBlock(
return [];
}
assert(ourNumber, 'Should have our number');
assertDev(ourNumber, 'Should have our number');
const securityNumber = await generateSecurityNumber(
ourNumber,
ourKey,

View file

@ -1,10 +1,10 @@
// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from './assert';
import { assertDev } from './assert';
export function shouldNeverBeCalled(..._args: ReadonlyArray<unknown>): void {
assert(false, 'This should never be called. Doing nothing');
assertDev(false, 'This should never be called. Doing nothing');
}
export async function asyncShouldNeverBeCalled(