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

@ -19,7 +19,7 @@ import * as groups from '../../groups';
import * as log from '../../logging/log';
import { calling } from '../../services/calling';
import { getOwn } from '../../util/getOwn';
import { assert, strictAssert } from '../../util/assert';
import { assertDev, strictAssert } from '../../util/assert';
import * as universalExpireTimer from '../../util/universalExpireTimer';
import type {
ShowSendAnywayDialogActiontype,
@ -1533,7 +1533,7 @@ function createGroup(
composer?.step !== ComposerStep.SetGroupMetadata ||
composer.isCreating
) {
assert(false, 'Cannot create group in this stage; doing nothing');
assertDev(false, 'Cannot create group in this stage; doing nothing');
return;
}
@ -1915,7 +1915,7 @@ function toggleConversationInChooseMembers(
maxRecommendedGroupSize + 1
);
assert(
assertDev(
maxGroupSize > maxRecommendedGroupSize,
'Expected the hard max group size to be larger than the recommended maximum'
);
@ -2157,7 +2157,10 @@ function closeComposerModal(
): ConversationsStateType {
const { composer } = state;
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
assert(false, "Can't close the modal in this composer step. Doing nothing");
assertDev(
false,
"Can't close the modal in this composer step. Doing nothing"
);
return state;
}
if (composer[modalToClose] !== OneTimeModalState.Showing) {
@ -2292,7 +2295,7 @@ export function reducer(
if (action.type === 'CLEAR_GROUP_CREATION_ERROR') {
const { composer } = state;
if (composer?.step !== ComposerStep.SetGroupMetadata) {
assert(
assertDev(
false,
"Can't clear group creation error in this composer state. Doing nothing"
);
@ -3263,7 +3266,7 @@ export function reducer(
case ComposerStep.SetGroupMetadata:
return state;
default:
assert(
assertDev(
false,
'Cannot transition to setting group metadata from this state'
);
@ -3285,7 +3288,10 @@ export function reducer(
},
};
default:
assert(false, 'Setting compose group avatar at this step is a no-op');
assertDev(
false,
'Setting compose group avatar at this step is a no-op'
);
return state;
}
}
@ -3304,7 +3310,7 @@ export function reducer(
},
};
default:
assert(false, 'Setting compose group name at this step is a no-op');
assertDev(false, 'Setting compose group name at this step is a no-op');
return state;
}
}
@ -3323,7 +3329,7 @@ export function reducer(
},
};
default:
assert(false, 'Setting compose group name at this step is a no-op');
assertDev(false, 'Setting compose group name at this step is a no-op');
return state;
}
}
@ -3331,7 +3337,7 @@ export function reducer(
if (action.type === 'SET_COMPOSE_SEARCH_TERM') {
const { composer } = state;
if (!composer) {
assert(
assertDev(
false,
'Setting compose search term with the composer closed is a no-op'
);
@ -3341,7 +3347,7 @@ export function reducer(
composer.step !== ComposerStep.StartDirectConversation &&
composer.step !== ComposerStep.ChooseGroupMembers
) {
assert(
assertDev(
false,
`Setting compose search term at step ${composer.step} is a no-op`
);
@ -3360,7 +3366,7 @@ export function reducer(
if (action.type === 'SET_IS_FETCHING_UUID') {
const { composer } = state;
if (!composer) {
assert(
assertDev(
false,
'Setting compose uuid fetch state with the composer closed is a no-op'
);
@ -3370,7 +3376,10 @@ export function reducer(
composer.step !== ComposerStep.StartDirectConversation &&
composer.step !== ComposerStep.ChooseGroupMembers
) {
assert(false, 'Setting compose uuid fetch state at this step is a no-op');
assertDev(
false,
'Setting compose uuid fetch state at this step is a no-op'
);
return state;
}
const { identifier, isFetching } = action.payload;
@ -3404,7 +3413,7 @@ export function reducer(
},
};
default:
assert(false, 'Setting editing avatar at this step is a no-op');
assertDev(false, 'Setting editing avatar at this step is a no-op');
return state;
}
}
@ -3430,7 +3439,7 @@ export function reducer(
},
};
default:
assert(false, 'Adding an avatar at this step is a no-op');
assertDev(false, 'Adding an avatar at this step is a no-op');
return state;
}
}
@ -3450,7 +3459,7 @@ export function reducer(
},
};
default:
assert(false, 'Removing an avatar at this step is a no-op');
assertDev(false, 'Removing an avatar at this step is a no-op');
return state;
}
}
@ -3478,7 +3487,7 @@ export function reducer(
},
};
default:
assert(false, 'Replacing an avatar at this step is a no-op');
assertDev(false, 'Replacing an avatar at this step is a no-op');
return state;
}
}
@ -3486,7 +3495,7 @@ export function reducer(
if (action.type === 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS') {
const { composer } = state;
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
assert(
assertDev(
false,
'Toggling conversation members is a no-op in this composer step'
);

View file

@ -25,7 +25,7 @@ import { SafetyNumberChangeSource } from '../../components/SafetyNumberChangeDia
import { StoryViewDirectionType, StoryViewModeType } from '../../types/Stories';
import { StoryRecipientUpdateEvent } from '../../textsecure/messageReceiverEvents';
import { ToastReactionFailed } from '../../components/ToastReactionFailed';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { blockSendUntilConversationsAreVerified } from '../../util/blockSendUntilConversationsAreVerified';
import { enqueueReactionForSend } from '../../reactions/enqueueReactionForSend';
import { getMessageById } from '../../messages/getMessageById';
@ -611,11 +611,11 @@ function sendStoryMessage(
return async (dispatch, getState) => {
const { stories } = getState();
const { openedAtTimestamp, sendStoryModalData } = stories;
assert(
assertDev(
openedAtTimestamp,
'sendStoryMessage: openedAtTimestamp is undefined, cannot send'
);
assert(
assertDev(
sendStoryModalData,
'sendStoryMessage: sendStoryModalData is not defined, cannot send'
);

View file

@ -28,7 +28,7 @@ import type { UUIDFetchStateType } from '../../util/uuidFetchState';
import { deconstructLookup } from '../../util/deconstructLookup';
import type { PropsDataType as TimelinePropsType } from '../../components/conversation/Timeline';
import type { TimelineItemType } from '../../components/conversation/TimelineItem';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
import { filterAndSortConversationsByRecent } from '../../util/filterAndSortConversations';
import type { ContactNameColorType } from '../../types/Colors';
@ -344,7 +344,7 @@ export const getMaximumGroupSizeModalState = createSelector(
case ComposerStep.SetGroupMetadata:
return composerState.maximumGroupSizeModalState;
default:
assert(
assertDev(
false,
'Can\'t get the maximum group size modal state in this composer state; returning "never shown"'
);
@ -361,7 +361,7 @@ export const getRecommendedGroupSizeModalState = createSelector(
case ComposerStep.SetGroupMetadata:
return composerState.recommendedGroupSizeModalState;
default:
assert(
assertDev(
false,
'Can\'t get the recommended group size modal state in this composer state; returning "never shown"'
);
@ -388,11 +388,14 @@ export const getComposerConversationSearchTerm = createSelector(
getComposerState,
(composer): string => {
if (!composer) {
assert(false, 'getComposerConversationSearchTerm: composer is not open');
assertDev(
false,
'getComposerConversationSearchTerm: composer is not open'
);
return '';
}
if (composer.step === ComposerStep.SetGroupMetadata) {
assert(
assertDev(
false,
'getComposerConversationSearchTerm: composer does not have a search term'
);
@ -406,14 +409,14 @@ export const getComposerUUIDFetchState = createSelector(
getComposerState,
(composer): UUIDFetchStateType => {
if (!composer) {
assert(false, 'getIsFetchingUsername: composer is not open');
assertDev(false, 'getIsFetchingUsername: composer is not open');
return {};
}
if (
composer.step !== ComposerStep.StartDirectConversation &&
composer.step !== ComposerStep.ChooseGroupMembers
) {
assert(
assertDev(
false,
`getComposerUUIDFetchState: step ${composer.step} ` +
'has no uuidFetchState key'
@ -583,7 +586,7 @@ const getGroupCreationComposerState = createSelector(
case ComposerStep.SetGroupMetadata:
return composerState;
default:
assert(
assertDev(
false,
'getSetGroupMetadataComposerState: expected step to be SetGroupMetadata'
);

View file

@ -3,7 +3,7 @@
import { createSelector } from 'reselect';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { getDomain } from '../../types/LinkPreview';
import type { LinkPreviewSourceType } from '../../types/LinkPreview';
@ -22,7 +22,10 @@ export const getLinkPreview = createSelector(
}
const domain = getDomain(linkPreview.url);
assert(domain !== undefined, "Domain of linkPreview can't be undefined");
assertDev(
domain !== undefined,
"Domain of linkPreview can't be undefined"
);
return {
...linkPreview,

View file

@ -21,7 +21,7 @@ import {
getBadgesSelector,
getPreferredBadgeSelector,
} from '../selectors/badges';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { SignalService as Proto } from '../../protobuf';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
import type { SmartChooseGroupMembersModalPropsType } from './ChooseGroupMembersModal';
@ -78,7 +78,7 @@ const mapStateToProps = (
): StateProps => {
const conversationSelector = getConversationByIdSelector(state);
const conversation = conversationSelector(props.conversationId);
assert(
assertDev(
conversation,
'<SmartConversationDetails> expected a conversation to be found'
);

View file

@ -10,7 +10,7 @@ import { getIntl } from '../selectors/user';
import * as log from '../../logging/log';
import type { Loadable } from '../../util/loadable';
import { LoadingState } from '../../util/loadable';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { explodePromise } from '../../util/explodePromise';
import { missingCaseError } from '../../util/missingCaseError';
import {
@ -134,7 +134,7 @@ export function SmartInstallScreen(): ReactElement {
let deviceName: string = normalizeDeviceName(state.deviceName);
if (!deviceName.length) {
// This should be impossible, but we have it here just in case.
assert(
assertDev(
false,
'Unexpected empty device name. Falling back to placeholder value'
);
@ -149,7 +149,7 @@ export function SmartInstallScreen(): ReactElement {
let hasCleanedUp = false;
const accountManager = window.getAccountManager();
assert(accountManager, 'Expected an account manager');
assertDev(accountManager, 'Expected an account manager');
const updateProvisioningUrl = (value: string): void => {
if (hasCleanedUp) {

View file

@ -14,7 +14,7 @@ import {
getConversationByUuidSelector,
} from '../selectors/conversations';
import { getGroupMemberships } from '../../util/getGroupMemberships';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import type { UUIDStringType } from '../../types/UUID';
export type SmartPendingInvitesProps = {
@ -32,7 +32,7 @@ const mapStateToProps = (
const conversationByUuidSelector = getConversationByUuidSelector(state);
const conversation = conversationSelector(props.conversationId);
assert(
assertDev(
conversation,
'<SmartPendingInvites> expected a conversation to be found'
);

View file

@ -38,7 +38,7 @@ import { renderEmojiPicker } from './renderEmojiPicker';
import { renderReactionPicker } from './renderReactionPicker';
import { getOwn } from '../../util/getOwn';
import { assert } from '../../util/assert';
import { assertDev } from '../../util/assert';
import { missingCaseError } from '../../util/missingCaseError';
import { getGroupMemberships } from '../../util/getGroupMemberships';
import {
@ -177,7 +177,7 @@ const getWarning = (
const conversationsWithSameTitle = getConversationsWithTitle(
conversation.title
);
assert(
assertDev(
conversationsWithSameTitle.length,
'Expected at least 1 conversation with the same title (this one)'
);